How to search an entire excel workbook for a particular string using powershell -


i need search particular string in excel spreadsheet has multiple sheets in it. looking way search entire contents of excel file similar find option in excel scope set workbook , not worksheet.

it nice if there similar search string particular string in regular file, (ie)

gci xcelfile.xls | select-string -pattern $mysearchstring 

i have searched internet , don't see existing information searching contents of existing excel file using powershell. hoping can pointers here me goal.

any assistance appreciated. don

opens excel

loads file

loops through each worksheet

searches range

loops through find next outputs index $column$row

exits excel

$file = "c:\test.xlsx" $searchstring = "test" $excel = new-object -comobject excel.application $workbook = $excel.workbooks.open($file) for($i = 1; $i -lt $($workbook.sheets.count() + 1); $i++){     $range = $workbook.sheets.item($i).range("a:z")     $target = $range.find($searchstring)     $first = $target         {         write-host "$i $($target.addresslocal())"         $target = $range.findnext($target)     }     while ($target -ne $null -and $target.addresslocal() -ne $first.addresslocal()) } $excel.quit() 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -