我需要将一些xlsx文件另存为xls文件,因为我们的SAS 9.2无法读取xlsx。
当我将它们保存在Powershell脚本中时,会收到此消息
我正在使用以下代码:
function convert_xlst_to_xls([string]$File) {
$Filepath = Get-Item -Path $File
Write-Host $Filepath
$NewFilepath = Join-Path -Path $FilePath.directory.FullName -ChildPath "$($Filepath.basename).xls"
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $true #or false
$workbook.CheckCompatibility = $false
$Workbook = $Excel.Workbooks.Open($Filepath.FullName, [Type]::Missing, $true)
if (Test-Path $NewFilepath) {
Remove-Item $NewFilepath
}
$Workbook.SaveAs($NewFilepath,56)
$Workbook.Close()
$Excel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Excel)
Remove-Variable Excel
return "$NewFilepath"
}
$New_Excel_File = convert_xlst_to_xls("$filePath")
它将不接受工作簿上的checkcompalility属性。
我的控制台:
The property 'CheckCompatibility' cannot be found on this object. Verify that the property exists and can be set. At S:\UO4\DWH\SIJ\CONVERT-EXCEL BACKGRUND3.ps1:32 char:1 + $workbook.CheckCompatibility = $false + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound
无论如何,是否存在强制保存另存为而不显示此兼容性控制的问题。