是否可以在PowerShell中找到包含特定字符串的所有单元格引用? $ Range.Find总是只返回工作表中的最后一个单元格,我想要所有单元格(或者我是否必须遍历每一行?呻吟)。
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $true
$Workbook = $Excel.Workbooks.Open("C:\Users\some.xlsx")
$MySheet = $Excel.Worksheets.Item("somesheet")
$Range = $MySheet.UsedRange
$Targets = $Range.Find("Cheese")
Foreach ($Target in $Targets)
{
Write-Host $Target.AddressLocal()
}
答案 0 :(得分:0)
我认为你应该使用:
$Target = $Range.Find("Cheese")
$First = $Target
Do
{
Write-Host $Target.AddressLocal()
$Target = $Range.FindNext($Target)
}
While ($Target -ne $NULL -and $Target.AddressLocal() -ne $First.AddressLocal())