Powershell find excel cell reference -


i using following powershell code search through excel document string , return true or false depending on if found.

if (test-path $filepath) { $wb = $xl.workbooks.open($filepath) if ([bool]$xl.cells.find("german")) {$found = 1} } 

i want able cell reference of string if found cant figure out or find answer on google. can help?

while there method search through entire workbook value, typically range.find method performed on worksheet. setting var workbook still using application search. should getting worksheet search workbook , using target of find operation.

following suggested modifications ps1.

$filepath = "t:\tmp\findit.xlsx" $xl = new-object -comobject excel.application $xl.visible = $true if (test-path $filepath) { $wb = $xl.workbooks.open($filepath) $ws = $xl.worksheets.item("sheet1") if ([bool]$ws.cells.find("german"))      {     $found = 1     write-host $found     write-host $ws.cells.find("german").address(0, 0, 1, 1)     } } 

to continue search occurrences use range.findnext method until loop original cell address.

$filepath = "t:\tmp\findit.xlsx" $xl = new-object -comobject excel.application $xl.visible = $true if (test-path $filepath) { $wb = $xl.workbooks.open($filepath) $ws = $wb.worksheets.item("sheet1")  $rc1 = $ws.cells.find("german") if ($rc1)      {     $found = 1     $addr = $rc1.address(0, 0, 1, 0)             {         $rc1 = $ws.cells.findnext($rc1)         write-host $rc1.address(0, 0, 1, 0)         } until ($addr -eq $rc1.address(0, 0, 1, 0))     } } 

it's hard provide more generalities since of code missing. i've filled in missing information own test environment.


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

html - Outlook 2010 Anchor (url/address/link) -

android - How to create dynamically Fragment pager adapter -