mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Prevent error: "Unable to get the SaveAs property of the Workbook class"
This commit is contained in:
@@ -47,12 +47,16 @@ function ConvertTo-ExcelXlsx {
|
||||
|
||||
try {
|
||||
$Excel.Visible = $false
|
||||
$null = $Excel.Workbooks.Open($xlsFile.FullName, $null, $true)
|
||||
$Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat)
|
||||
$workbook = $Excel.Workbooks.Open($xlsFile.FullName, $null, $true)
|
||||
if ($null -eq $workbook) {
|
||||
Write-Host "Failed to open workbook"
|
||||
} else {
|
||||
$workbook.SaveAs($xlsxPath, $xlFixedFormat)
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if ($null -ne $Excel.ActiveWorkbook) {
|
||||
$Excel.ActiveWorkbook.Close()
|
||||
if ($null -ne $workbook) {
|
||||
$workbook.Close()
|
||||
}
|
||||
|
||||
$Excel.Quit()
|
||||
|
||||
Reference in New Issue
Block a user