diff --git a/Examples/HeaderName/ConvertDictionaryOfArraysToExcel.ps1 b/Examples/HeaderName/ConvertDictionaryOfArraysToExcel.ps1 new file mode 100644 index 0000000..81bfb43 --- /dev/null +++ b/Examples/HeaderName/ConvertDictionaryOfArraysToExcel.ps1 @@ -0,0 +1,24 @@ +function ConvertTo-Excel { + param( + $Path, + [System.Collections.IDictionary]$targetData + ) + + $column = 1 + foreach ($key in $targetData.Keys) { + $cityData[$key] | Export-Excel $xlfile -StartColumn ($column++) -HeaderName $key -AutoSize + } +} + +$cityData = [Ordered]@{} + +$cityData.City = "New York City", "Paris", "Barcelona", "Rome" +$cityData.Country = "United States", "France", "Spain", "Italy" +$cityData.Population = 8600000, 2141000, 5515000, 2873000 + +$xlfile = "$PSScriptRoot/test.xlsx" +Remove-Item $xlfile -ErrorAction SilentlyContinue + +ConvertTo-Excel $xlfile $cityData + +. $xlfile \ No newline at end of file diff --git a/Examples/HeaderName/HeaderName.ps1 b/Examples/HeaderName/HeaderName.ps1 new file mode 100644 index 0000000..841a0b7 --- /dev/null +++ b/Examples/HeaderName/HeaderName.ps1 @@ -0,0 +1,24 @@ +try { Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 } catch { throw ; return } + +## This exports only the numbers +# 1..10 | Export-excel $PSScriptRoot\test.xlsx -Show + +## This exports the numbers and in A1 the text "MyNum" +# 1..10 | Export-excel $PSScriptRoot\test.xlsx -HeaderName MyNum -Show + +$xlfile = "$PSScriptRoot/testMultipleColumns.xlsx" +Remove-Item $xlfile -ErrorAction SilentlyContinue + +$Regions = 'West', 'North', 'East ', 'East ', 'West ', 'North', 'South', 'North', 'South' +$States = 'Texas', 'Tennessee', 'Florida', 'Maine', 'Virginia', 'Missouri', 'Kansas', 'North Dakota', 'Delaware' +$Units = 927, 466, 520, 828, 465, 436, 214, 789, 712 +$Prices = 923.71, 770.67, 458.68, 661.24, 53.58, 235.67, 992.47, 640.72, 508.55 + +# Export each list (array) as a separate column to the same worksheet and workbook +$Regions | Export-Excel -Path $xlfile -HeaderName Region -StartColumn 1 -AutoSize +$States | Export-Excel -Path $xlfile -HeaderName State -StartColumn 2 -AutoSize +$Units | Export-Excel -Path $xlfile -HeaderName Units -StartColumn 3 -AutoSize +$Prices | Export-Excel -Path $xlfile -HeaderName Prices -StartColumn 4 -AutoSize + +# Show the results in Excel +. $xlfile \ No newline at end of file