通过PoSh保存/关闭.xls文件时禁用Excel兼容性检查器

时间:2014-02-05 18:03:50

标签: excel powershell excel-2007 excel-2010 powershell-v2.0

我正在使用PoSh脚本打开/编辑/保存/关闭.xls文件。当文件打开时,我很确定它是由Excel 2010处理的。

我正在使用找到here的脚本,除了指向我的文件路径之外没有做任何更改。

它就像我需要它一样工作,但当它处于进程的保存/关闭阶段时,Excel兼容性检查器出现,我必须单击“确定”才能提交。

有没有办法在PoSh脚本中禁用兼容性检查器?

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!

答案 1 :(得分:0)

我尝试添加$workbook.CheckCompatibility = $False但没有成功。 通过添加此行也解决了这个问题: $Excel.displayalerts = $false