Powershell 脚本 - 打开 Excel、更新外部数据、另存为 [英] Powershell Script - Open Excel, Update External Data, Save as

查看:10
本文介绍了Powershell 脚本 - 打开 Excel、更新外部数据、另存为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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()

这篇关于Powershell 脚本 - 打开 Excel、更新外部数据、另存为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆