From fbae59b386a0975da3629758317927ba783f2002 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sat, 31 Aug 2019 19:40:42 -0400 Subject: [PATCH 1/3] Bumped the version --- .gitignore | 2 ++ ImportExcel.psd1 | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 7a4ebe0..a50db38 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,5 @@ ImportExcel.zip .vscode/settings.json ~$* +InstallModule.ps1 +PublishToGallery.ps1 diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index 0a930f1..3ed5f48 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -4,7 +4,7 @@ RootModule = 'ImportExcel.psm1' # Version number of this module. - ModuleVersion = '6.5.0' + ModuleVersion = '6.5.1' # ID used to uniquely identify this module GUID = '60dd4136-feff-401a-ba27-a84458c57ede' From e45c07c40b8938b58687aa6d73f6f67b8d9cf17b Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 22 Sep 2019 11:43:47 -0400 Subject: [PATCH 2/3] Add ReadAllSheets example, update readme bump version --- Examples/ReadAllSheets/ReadAllSheets.ps1 | 60 ++++++++++++++++++++++++ ImportExcel.psd1 | 2 +- README.md | 4 ++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 Examples/ReadAllSheets/ReadAllSheets.ps1 diff --git a/Examples/ReadAllSheets/ReadAllSheets.ps1 b/Examples/ReadAllSheets/ReadAllSheets.ps1 new file mode 100644 index 0000000..f3a237c --- /dev/null +++ b/Examples/ReadAllSheets/ReadAllSheets.ps1 @@ -0,0 +1,60 @@ +$sheet1 = ConvertFrom-Csv @" +Region,Item,TotalSold +West,melon,27 +North,avocado,21 +West,kiwi,84 +East,melon,23 +North,kiwi,8 +North,nail,29 +North,kiwi,46 +South,nail,83 +East,pear,10 +South,avocado,40 +"@ + +$sheet2 = ConvertFrom-Csv @" +Region,Item,TotalSold +West,lemon,24 +North,hammer,41 +East,nail,87 +West,lemon,68 +North,screwdriver,9 +North,drill,76 +West,lime,28 +West,pear,78 +North,apple,95 +South,melon,40 +"@ + +$sheet3 = ConvertFrom-Csv @" +Region,Item,TotalSold +South,drill,100 +East,saw,22 +North,saw,5 +West,orange,78 +East,saw,27 +North,screwdriver,57 +South,hammer,66 +East,saw,62 +West,nail,98 +West,nail,98 +"@ + +$xlfile = "$env:TEMP\MultipleSheets.xlsx" +Remove-Item $xlfile -ErrorAction SilentlyContinue + +$sheet1 | Export-Excel $xlfile -WorksheetName Sheet1 +$sheet2 | Export-Excel $xlfile -WorksheetName Sheet2 +$sheet3 | Export-Excel $xlfile -WorksheetName Sheet3 + +# Read all the sheets in the workbook +$hash = @{ } +$e = Open-ExcelPackage $xlfile +foreach ($sheet in $e.workbook.worksheets) { + $hash[$sheet.name] = Import-Excel -ExcelPackage $e -WorksheetName $sheet.name +} + +Close-ExcelPackage $e -NoSave + +# Output Sheet1 +$hash.Sheet1 \ No newline at end of file diff --git a/ImportExcel.psd1 b/ImportExcel.psd1 index 3ed5f48..a74ca84 100644 --- a/ImportExcel.psd1 +++ b/ImportExcel.psd1 @@ -4,7 +4,7 @@ RootModule = 'ImportExcel.psm1' # Version number of this module. - ModuleVersion = '6.5.1' + ModuleVersion = '6.5.2' # ID used to uniquely identify this module GUID = '60dd4136-feff-401a-ba27-a84458c57ede' diff --git a/README.md b/README.md index 22904e5..b608c65 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,10 @@ Install-Module ImportExcel -scope CurrentUser Install-Module ImportExcel ``` +# What's new 6.5.2 + +- Added the example ReadAllSheets.ps1 based on the thread https://github.com/dfinke/ImportExcel/issues/678 + # What's new 6.5.0 This is now using the latest version of EPPlus. Unit tests are updated and passing, if you hit problems, please open an issue. From 9e92f2dbc62ead97a78ad64bd11c033fb8cf7822 Mon Sep 17 00:00:00 2001 From: dfinke Date: Sun, 22 Sep 2019 11:58:13 -0400 Subject: [PATCH 3/3] Refactored --- Examples/ReadAllSheets/GenerateXlsx.ps1 | 54 +++++++++++++++++++ Examples/ReadAllSheets/Get-ExcelSheets.ps1 | 19 +++++++ Examples/ReadAllSheets/ReadAllSheets.ps1 | 62 ++-------------------- 3 files changed, 76 insertions(+), 59 deletions(-) create mode 100644 Examples/ReadAllSheets/GenerateXlsx.ps1 create mode 100644 Examples/ReadAllSheets/Get-ExcelSheets.ps1 diff --git a/Examples/ReadAllSheets/GenerateXlsx.ps1 b/Examples/ReadAllSheets/GenerateXlsx.ps1 new file mode 100644 index 0000000..7b42ea1 --- /dev/null +++ b/Examples/ReadAllSheets/GenerateXlsx.ps1 @@ -0,0 +1,54 @@ +param( + [Parameter(Mandatory)] + $path +) + +$sheet1 = ConvertFrom-Csv @" +Region,Item,TotalSold +West,melon,27 +North,avocado,21 +West,kiwi,84 +East,melon,23 +North,kiwi,8 +North,nail,29 +North,kiwi,46 +South,nail,83 +East,pear,10 +South,avocado,40 +"@ + +$sheet2 = ConvertFrom-Csv @" +Region,Item,TotalSold +West,lemon,24 +North,hammer,41 +East,nail,87 +West,lemon,68 +North,screwdriver,9 +North,drill,76 +West,lime,28 +West,pear,78 +North,apple,95 +South,melon,40 +"@ + +$sheet3 = ConvertFrom-Csv @" +Region,Item,TotalSold +South,drill,100 +East,saw,22 +North,saw,5 +West,orange,78 +East,saw,27 +North,screwdriver,57 +South,hammer,66 +East,saw,62 +West,nail,98 +West,nail,98 +"@ + +Remove-Item $path -ErrorAction SilentlyContinue + +$sheet1 | Export-Excel $path -WorksheetName Sheet1 +$sheet2 | Export-Excel $path -WorksheetName Sheet2 +$sheet3 | Export-Excel $xlfile -WorksheetName Sheet3 + +$path \ No newline at end of file diff --git a/Examples/ReadAllSheets/Get-ExcelSheets.ps1 b/Examples/ReadAllSheets/Get-ExcelSheets.ps1 new file mode 100644 index 0000000..0b089ae --- /dev/null +++ b/Examples/ReadAllSheets/Get-ExcelSheets.ps1 @@ -0,0 +1,19 @@ +# Get-ExcelSheets + +param( + [Parameter(Mandatory)] + $path +) + + +$hash = @{ } + +$e = Open-ExcelPackage $path + +foreach ($sheet in $e.workbook.worksheets) { + $hash[$sheet.name] = Import-Excel -ExcelPackage $e -WorksheetName $sheet.name +} + +Close-ExcelPackage $e -NoSave + +$hash \ No newline at end of file diff --git a/Examples/ReadAllSheets/ReadAllSheets.ps1 b/Examples/ReadAllSheets/ReadAllSheets.ps1 index f3a237c..5bc26d4 100644 --- a/Examples/ReadAllSheets/ReadAllSheets.ps1 +++ b/Examples/ReadAllSheets/ReadAllSheets.ps1 @@ -1,60 +1,4 @@ -$sheet1 = ConvertFrom-Csv @" -Region,Item,TotalSold -West,melon,27 -North,avocado,21 -West,kiwi,84 -East,melon,23 -North,kiwi,8 -North,nail,29 -North,kiwi,46 -South,nail,83 -East,pear,10 -South,avocado,40 -"@ +$xlfile = "$env:TEMP\MultipleSheets.xlsx" -$sheet2 = ConvertFrom-Csv @" -Region,Item,TotalSold -West,lemon,24 -North,hammer,41 -East,nail,87 -West,lemon,68 -North,screwdriver,9 -North,drill,76 -West,lime,28 -West,pear,78 -North,apple,95 -South,melon,40 -"@ - -$sheet3 = ConvertFrom-Csv @" -Region,Item,TotalSold -South,drill,100 -East,saw,22 -North,saw,5 -West,orange,78 -East,saw,27 -North,screwdriver,57 -South,hammer,66 -East,saw,62 -West,nail,98 -West,nail,98 -"@ - -$xlfile = "$env:TEMP\MultipleSheets.xlsx" -Remove-Item $xlfile -ErrorAction SilentlyContinue - -$sheet1 | Export-Excel $xlfile -WorksheetName Sheet1 -$sheet2 | Export-Excel $xlfile -WorksheetName Sheet2 -$sheet3 | Export-Excel $xlfile -WorksheetName Sheet3 - -# Read all the sheets in the workbook -$hash = @{ } -$e = Open-ExcelPackage $xlfile -foreach ($sheet in $e.workbook.worksheets) { - $hash[$sheet.name] = Import-Excel -ExcelPackage $e -WorksheetName $sheet.name -} - -Close-ExcelPackage $e -NoSave - -# Output Sheet1 -$hash.Sheet1 \ No newline at end of file +.\GenerateXlsx.ps1 $xlfile +.\Get-ExcelSheets.ps1 $xlfile \ No newline at end of file