【问题标题】:disable Excel Compatibility Checker when saving/closing .xls file via PoSh通过 PoSh 保存/关闭 .xls 文件时禁用 Excel 兼容性检查器
【发布时间】:2014-03-02 08:09:20
【问题描述】:
我正在使用 PoSh 脚本打开/编辑/保存/关闭 .xls 文件。当文件打开时,我很确定它是由 Excel 2010 处理的。
我正在使用找到的脚本here,除了指向我的文件路径之外没有进行任何更改。
它就像我需要它一样工作,但是当它处于进程的保存/关闭阶段时,会出现 Excel 兼容性检查器,我必须单击“确定”才能提交。
有什么方法可以禁用 PoSh 脚本中的兼容性检查器?
【问题讨论】:
标签:
excel
powershell
excel-2007
excel-2010
powershell-2.0
【解决方案1】:
我想通了。
我在打开工作簿后添加了以下行:
$workbook.CheckCompatibility = $False
脚本全文如下:
$excel = new-object -com Excel.Application -Property @{Visible = $false}
$workbook = $excel.Workbooks.Open($file) # Open the file
$workbook.CheckCompatibility = $False
$sheet = $workbook.Sheets.Item("Paste value") # Select appropriate worksheet
[void]$sheet.Cells.Item(1, 1).EntireRow.Delete() # Delete the first row
$workbook.Close($true) # Close workbook and save changes
$excel.quit() # Quit Excel
[Runtime.Interopservices.Marshal]::ReleaseComObject($excel) # Release COM
我喜欢 PowerShell!
【解决方案2】:
我尝试添加$workbook.CheckCompatibility = $False,但没有成功。
通过添加此行也解决了这个问题:
$Excel.displayalerts = $false