Add ReadAllSheets example, update readme bump version

This commit is contained in:
dfinke
2019-09-22 11:43:47 -04:00
parent fbae59b386
commit e45c07c40b
3 changed files with 65 additions and 1 deletions

View File

@@ -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