.net - Given the name of an excel cell, how can i find its value? -


so in excel, can assign cells names avoid using row , column numbers. in case, useful because i'm dealing several excel sheets , not know particular cell be.

how can value of cell? i'm looping through entire worksheet looking it, stumbled across online, speed application considerably.

if found posts online suggest either xlworksheet.cells("cellname").value or xlworksheet.getcell("cellname").value. unfortunately cells method not accept string argument , getcell method not exist. i'm using interop library. thank in advance.

edit: range("myname") 1 way, if you're in vba, shortest way value of range use evaluate function shorthand: [myname] return named range called myname

enter image description here

or powershell (which uses com .net):

$excel.evaluate("myname").value() 

original answer: have tried worksheet.names , workbook.names

thisworkbook.names("myname").referstorange.value

proof works through com automation / vsto / powershell:

powershell screenshot

$file = "c:\users\vincent\desktop\test.xls"  $excel = new-object -comobject excel.application $excel.visible = $false $workbook = $excel.workbooks.open("c:\users\vincent\desktop\test.xls")  $workbook.names.item("myname").referstorange.value() 

also note scope of named range matters in how access it:

name manager scope


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -