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

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

我正在使用这里find的脚本,除了指向我的文件path以外没有任何更改。

它的工作方式就像我需要它的工作,但是当它处于进程的保存/closures阶段时,将出现Excel兼容性检查程序,并且必须单击“确定”才能提交。

有什么办法来禁用PoSh脚本中的兼容性检查器?

我想到了。

打开工作簿后,我添加了以下行: $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!

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