【发布时间】:2019-06-02 16:46:13
【问题描述】:
打开模板.xls
搜索“ok”字符串
为找到的每个结果打印地址本地
color ColorIndex = 3 出现“ok”的每一行
保存excel表格,关闭
我的问题是,虽然我在 Write-Host 上打印出正确的搜索结果,但我无法更改找到的结果行的颜色!!
这段代码正在运行。
$file = 'C:\Users\bigadmin\Desktop\Projects\AutoUpdate\Template.xls'
$xl = new-object -c excel.application
$wb1 = $xl.workbooks.open($file, $null, $true)
$ws1 = $wb1.WorkSheets.item(1)
$ws1.activate()
$Range = $WS1.Range("A100:D110")
$Target = $Range.Find("OK")
$First = $Target
Do
{
Write-Host $Target.AddressLocal()
$Target.EntireRow.Interior.ColorIndex = 3
$Target = $Range.FindNext($Target)
}
While ($Target -ne $NULL -and $Target.AddressLocal() -ne
$First.AddressLocal())
$wb1.Save()
$wb1.close($true)
$xl.quit()
spps -n excel
【问题讨论】:
-
您可以更改 Excel 文件中的任何内容吗?例如。在目标单元格中输入“hello world”?
标签: excel powershell