.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
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:
$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:
Comments
Post a Comment