【发布时间】:2021-07-07 19:47:44
【问题描述】:
我有以下代码可以打开电子表格,删除所有连接并“保存”一个新文件。
$a = New-Object -COM "Excel.Application"
$a.Visible = $false
$b = $a.Workbooks.Open("F:\Scripts\All Users.xlsx")
do
{
$b.Connections.Item(1).Delete()
$Count = $b.Connections.Count()
} until($Count -eq 0)
$b.SaveAs("F:\Scripts\Users Home Drive Search.xlsx")
$b.Close()
我想知道两件事:
- 如何让工作表刷新所有连接?我试过“$b.Connections.refreshall()”,但 refreshall() 不存在。
- 如何退出 Excel 应用程序?我运行了“New-Object -COM "Excel.Application" | Get-Member -MemberType Methods”,但没有看到退出或退出方法。
【问题讨论】:
标签: excel powershell