Close the $Stream so the xlsx won't be locked

This commit is contained in:
dfinke
2019-01-05 09:49:48 -05:00
parent c2525b0348
commit 86b5c13543
2 changed files with 41 additions and 38 deletions

View File

@@ -98,6 +98,7 @@
} }
Write-Verbose "Copying $($SourceWorkSheet) from $($SourceWorkbook) to $($DestinationWorkSheet) in $($DestinationWorkbook)" Write-Verbose "Copying $($SourceWorkSheet) from $($SourceWorkbook) to $($DestinationWorkSheet) in $($DestinationWorkbook)"
$null = Add-WorkSheet -ExcelWorkbook $wb -WorkSheetname $DestinationWorkSheet -CopySource $sourceWs $null = Add-WorkSheet -ExcelWorkbook $wb -WorkSheetname $DestinationWorkSheet -CopySource $sourceWs
if ($Stream) {$Stream.Close() }
if ($package1) {Close-ExcelPackage -ExcelPackage $Package1 -NoSave } if ($package1) {Close-ExcelPackage -ExcelPackage $Package1 -NoSave }
if ($package2) {Close-ExcelPackage -ExcelPackage $Package2 -Show:$show } if ($package2) {Close-ExcelPackage -ExcelPackage $Package2 -Show:$show }
if ($show -and $DestinationWorkbook -is [OfficeOpenXml.ExcelWorkbook]) { if ($show -and $DestinationWorkbook -is [OfficeOpenXml.ExcelWorkbook]) {

View File

@@ -109,6 +109,8 @@ Describe "Copy-Worksheet" {
} }
$targetSheets | ForEach-Object { Remove-WorkSheet -FullName $xlfile -WorksheetName $_ } $targetSheets | ForEach-Object { Remove-WorkSheet -FullName $xlfile -WorksheetName $_ }
(Get-ExcelSheetInfo -Path $xlfile ).Count | Should Be 3
} }
} }
} }