Powershell 脚本 - 打开 Excel、更新外部数据、另存为另存为、脚本、数据、Powershell

由网友(花月夜)分享简介:有没有人可以帮助我编写这个脚本.Is anyone able to help me with this script. $file = 'C:ScriptsSpreadsheet.xlsx'$x1 = New-Object -ComObject "Excel.Application"$x1.Visible =...

有没有人可以帮助我编写这个脚本.

Is anyone able to help me with this script.

$file = 'C:ScriptsSpreadsheet.xlsx'
$x1 = New-Object -ComObject "Excel.Application"
$x1.Visible = $false
$enddate = (Get-Date).tostring("dd-MM-yy")
$filename = 'C:ScriptsSpreadsheet ' + $enddate + '.xlsx'
$wb = $x1.workbooks.Open($file)
$wb.refreshall
$wb.SaveAs($filename)
$wb.Close()
$x1.Quit()
Remove-Variable wb,x1

工作簿通过 ODBC 连接打开并使用外部数据更新其数据透视表.当您手动打开工作簿时,它会刷新.当您使用脚本打开它时,它只是打开而不刷新数据.

The workbook opens and updates its pivot table with external data through an ODBC connection. When you open the workbook manually it refreshes. When you open it with the script it just opens and does not refresh the data.

我尝试了以下方法:

选中复选框始终使用连接文件"在excel中保存数据源的密码禁用启用后台刷新"和所有其他刷新选项创建了一个宏以在工作簿打开时自动刷新数据源

任何帮助将不胜感激,谢谢!

Any help would be appreciated, thanks!

推荐答案

改变

$wb.RefreshAll

$wb.RefreshAll()
阅读全文

相关推荐

最新文章