fix: handle file paths with spaces and special characters in Excel conversion
This commit is contained in:
parent
dfb9dc3557
commit
b55058161a
@ -473,6 +473,10 @@ function Convert-Files {
|
||||
$xlsxPath = Join-Path $env:TEMP $xlsxFileName
|
||||
$downloadPath = Join-Path $env:TEMP $originalFileName
|
||||
|
||||
# Convert the paths to proper Windows paths
|
||||
$xlsxPath = [System.IO.Path]::GetFullPath($xlsxPath)
|
||||
$downloadPath = [System.IO.Path]::GetFullPath($downloadPath)
|
||||
|
||||
try {
|
||||
# Open Excel
|
||||
$excel = New-Object -ComObject Excel.Application
|
||||
@ -482,12 +486,14 @@ function Convert-Files {
|
||||
try {
|
||||
$workbook = $excel.Workbooks.Open($downloadPath)
|
||||
|
||||
# Save as XLSX - use the full path with quotes
|
||||
# Save as XLSX using the full path
|
||||
$workbook.SaveAs([string]$xlsxPath, 51) # 51 = xlOpenXMLWorkbook (*.xlsx)
|
||||
$workbook.Close($false)
|
||||
$workbook.Close($true) # True to save changes
|
||||
|
||||
Start-Sleep -Seconds 1 # Give Excel time to finish saving
|
||||
|
||||
# Verify the file was created
|
||||
if (-not (Test-Path $xlsxPath)) {
|
||||
if (-not (Test-Path -LiteralPath $xlsxPath)) {
|
||||
throw "Excel SaveAs succeeded but file not found at: $xlsxPath"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user