Error saving after using Add-Worksheet with this specific file
mavhc opened this issue · comments
mavhc commented
scienceTemplate.xlsx
test.xlsx
Version 7.8.6
Using the 2 files attached, the follow code gives an error
$template = Open-ExcelPackage "scienceTemplate.xlsx"
$wsScience = $template.Workbook.Worksheets["Science"]
$destination = "test.xlsx"
$excel = Open-ExcelPackage $destination
$ws = Add-Worksheet -ExcelPackage $excel -WorkSheetname "Science" -ClearSheet -CopySource $wsScience
Close-ExcelPackage $excel
Results in:
At C:\Program Files\WindowsPowerShell\Modules\ImportExcel\7.8.6\Public\Close-ExcelPackage.ps1:29 char:20
+ else { $ExcelPackage.Save() }
Using a simpler template file works fine, tried to find a minimal case, and ended up deleting everything, so possibly something about the formatting is the problem?
Doug Finke commented
possible. please post a simpler repro with data, and the scritp and I can take a look
Doug Finke commented
So this works. I'm wondering if the issue is that the science sheet you have has formatting in it.
$xlSrc = "$PSScriptRoot\ImportExcelExample.xlsx"
$xlDst = "$PSScriptRoot\myTest.xlsx"
Remove-Item $xlSrc -ErrorAction Ignore
Remove-Item $xlDst -ErrorAction Ignore
1..10 | Export-Excel $xlSrc
$src = Open-ExcelPackage $xlSrc
$dst = Open-ExcelPackage $xlDst -Create
$null = Add-Worksheet -ExcelPackage $dst -WorksheetName Test -CopySource $src.Sheet1 -ClearSheet
Close-ExcelPackage $src
Close-ExcelPackage $dst -Show