mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-15 07:43:23 +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 {
|
try {
|
||||||
$Excel.Visible = $false
|
$Excel.Visible = $false
|
||||||
$null = $Excel.Workbooks.Open($xlsFile.FullName, $null, $true)
|
$workbook = $Excel.Workbooks.Open($xlsFile.FullName, $null, $true)
|
||||||
$Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat)
|
if ($null -eq $workbook) {
|
||||||
|
Write-Host "Failed to open workbook"
|
||||||
|
} else {
|
||||||
|
$workbook.SaveAs($xlsxPath, $xlFixedFormat)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if ($null -ne $Excel.ActiveWorkbook) {
|
if ($null -ne $workbook) {
|
||||||
$Excel.ActiveWorkbook.Close()
|
$workbook.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
$Excel.Quit()
|
$Excel.Quit()
|
||||||
|
|||||||
Reference in New Issue
Block a user