fix: Add error handling for Excel SaveAs operation in Convert-Files function

This commit is contained in:
Bobby Abellana (aider) 2025-02-21 11:30:09 -08:00
parent e615e043e3
commit ffbe44da0a

View File

@ -482,9 +482,15 @@ function Convert-Files {
$workbook = $excel.Workbooks.Open($downloadPath)
Write-Host "Saving as XLSX: $xlsxPath"
# Save directly to the final path
$workbook.SaveAs([string]$xlsxPath, 51) # 51 = xlWorkbookDefault (xlsx format)
$workbook.Close($true)
try {
# Save directly to the final path
$workbook.SaveAs([string]$xlsxPath, 51) # 51 = xlWorkbookDefault (xlsx format)
$workbook.Close($true)
}
catch {
$script:txtStatus.Text += "Error during SaveAs: $($_.Exception.Message)`n"
throw "SaveAs failed: $($_.Exception.Message)" # Re-throw the exception to be caught by the outer catch
}
Start-Sleep -Seconds 2 # Give Excel time to finish