Skip to content

Commit

Permalink
Merge pull request #1603 from edwardmiller-mesirow/read-only
Browse files Browse the repository at this point in the history
[ConvertTo-ExcelXlsx] open XLS as read-only
  • Loading branch information
dfinke authored May 18, 2024
2 parents 63683db + 36b5495 commit a1418a3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Public/ConvertTo-ExcelXlsx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,18 @@ function ConvertTo-ExcelXlsx {
throw "Could not create Excel.Application ComObject. Please verify that Excel is installed."
}

$Excel.Visible = $false
$null = $Excel.Workbooks.Open($xlsFile.FullName)
$Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat)
$Excel.ActiveWorkbook.Close()
$Excel.Quit()
try {
$Excel.Visible = $false
$null = $Excel.Workbooks.Open($xlsFile.FullName, $null, $true)
$Excel.ActiveWorkbook.SaveAs($xlsxPath, $xlFixedFormat)
}
finally {
if ($null -ne $Excel.ActiveWorkbook) {
$Excel.ActiveWorkbook.Close()
}

$Excel.Quit()
}
}
}

0 comments on commit a1418a3

Please sign in to comment.