What I'm doing here is to search excel sheet for a value, if value matches it will be replaced by first value in a given text file:
example:
search for value text find the first instance replace with first value in a given text file which is "read", search again for text find again replace with "read" until can't find "text", now search for second value in array "text1", search in excel sheet find it replace with second line in given text value, which is "read1" and so on.
I have the script that is working somewhat, issue is it will replace all array values with only first line of text file which is "read", it is not looping through the second line of text file.
Can someone please help.
code:
test.txt file read as:
read
read1
read2
$text="text","text1","text2","text3"$replace=get-contentC:\script\test.txt$File="C:\script\test.xlsx"# Setup Excel, open $File and set the the first worksheet$i=0$Excel=New-Object-ComObjectExcel.Application$Excel.visible=$true$Workbook=$Excel.workbooks.open($file)$Worksheets=$Workbooks.worksheets$Worksheet=$Workbook.Worksheets.Item(1)$Range=$Worksheet.Range("A1","Z10").EntireColumnForeach($SearchStringin$text){$Search=$Range.find($SearchString)if($search-ne$null){$SearchString$replace[$i]$FirstAddress=$search.Addressdo{$Search.value()=$replace[$i]$search=$Range.FindNext($search)}while($search-ne$null-and$search.Address-ne$FirstAddress)$i++}}$WorkBook.Save()$WorkBook.Close()[void]$excel.quit()