mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Merge pull request #520 from dfinke/FixCopyExcelWorksheetStreamClose-dcf
Fix Copy-ExcelWorkSheet so Remove-WorkSheet works. Resolves #516
This commit is contained in:
@@ -98,6 +98,7 @@
|
||||
}
|
||||
Write-Verbose "Copying $($SourceWorkSheet) from $($SourceWorkbook) to $($DestinationWorkSheet) in $($DestinationWorkbook)"
|
||||
$null = Add-WorkSheet -ExcelWorkbook $wb -WorkSheetname $DestinationWorkSheet -CopySource $sourceWs
|
||||
if ($Stream) {$Stream.Close() }
|
||||
if ($package1) {Close-ExcelPackage -ExcelPackage $Package1 -NoSave }
|
||||
if ($package2) {Close-ExcelPackage -ExcelPackage $Package2 -Show:$show }
|
||||
if ($show -and $DestinationWorkbook -is [OfficeOpenXml.ExcelWorkbook]) {
|
||||
|
||||
@@ -56,12 +56,12 @@ Install-Module ImportExcel
|
||||
# What's new 5.4.4
|
||||
|
||||
- Fix issue when only a single property is piped into Export-Excel
|
||||
- Fix issue in `Copy-ExcelWorksheet`, close the `$Stream`
|
||||
|
||||
# What's new 5.4.3
|
||||
|
||||
- Added Remove-Worksheet: Removes one or more worksheets from one or more workbooks
|
||||
|
||||
|
||||
# What's new 5.4.2
|
||||
|
||||
- Added parameters -GroupDateRow and -GroupDatePart & -GroupNumericRow, -GroupNumericMin, -GroupNumericMax and -GroupNumericInterval
|
||||
|
||||
@@ -4,8 +4,8 @@ Remove-item -Path $path1, $path2 -ErrorAction SilentlyContinue
|
||||
|
||||
$ProcRange = Get-Process | Export-Excel $path1 -DisplayPropertySet -WorkSheetname Processes -ReturnRange
|
||||
|
||||
if ((Get-Culture).NumberFormat.CurrencySymbol -eq "<EFBFBD>") {$OtherCurrencySymbol = "$"}
|
||||
else {$OtherCurrencySymbol = "<EFBFBD>"}
|
||||
if ((Get-Culture).NumberFormat.CurrencySymbol -eq "<EFBFBD>") {$OtherCurrencySymbol = "$"}
|
||||
else {$OtherCurrencySymbol = "<EFBFBD>"}
|
||||
[PSCustOmobject][Ordered]@{
|
||||
Date = Get-Date
|
||||
Formula1 = '=SUM(F2:G2)'
|
||||
@@ -85,4 +85,32 @@ Describe "Copy-Worksheet" {
|
||||
($ws.Cells[2, 20].Value -is [valuetype] ) | Should be $true
|
||||
}
|
||||
}
|
||||
|
||||
Context "Copy worksheet should close all files" {
|
||||
BeforeAll {
|
||||
$xlfile = "$env:TEMP\reports.xlsx"
|
||||
$xlfileArchive = "$env:TEMP\reportsArchive.xlsx"
|
||||
|
||||
rm $xlfile -ErrorAction SilentlyContinue
|
||||
rm $xlfileArchive -ErrorAction SilentlyContinue
|
||||
|
||||
$sheets = echo 1.1.2019 1.2.2019 1.3.2019 1.4.2019 1.5.2019
|
||||
|
||||
$sheets | ForEach-Object {
|
||||
"Hello World" | Export-Excel $xlfile -WorksheetName $_
|
||||
}
|
||||
}
|
||||
|
||||
it "Should copy and remove sheets" {
|
||||
$targetSheets = echo 1.1.2019 1.4.2019
|
||||
|
||||
$targetSheets | ForEach-Object {
|
||||
Copy-ExcelWorkSheet -SourceWorkbook $xlfile -DestinationWorkbook $xlfileArchive -SourceWorkSheet $_ -DestinationWorkSheet $_
|
||||
}
|
||||
|
||||
$targetSheets | ForEach-Object { Remove-WorkSheet -FullName $xlfile -WorksheetName $_ }
|
||||
|
||||
(Get-ExcelSheetInfo -Path $xlfile ).Count | Should Be 3
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user