fix: Add error handling for Excel SaveAs operation in Convert-Files function
This commit is contained in:
parent
e615e043e3
commit
ffbe44da0a
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user