diff --git a/Examples/ConditionalFormatting/Top10-DataBar-TwoColorScale.ps1 b/Examples/ConditionalFormatting/Top10-DataBar-TwoColorScale.ps1 index 932b109..4680c1a 100644 --- a/Examples/ConditionalFormatting/Top10-DataBar-TwoColorScale.ps1 +++ b/Examples/ConditionalFormatting/Top10-DataBar-TwoColorScale.ps1 @@ -1,7 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$xlfile = "$env:TEMP\test.xlsx" -Remove-Item $xlfile -ErrorAction SilentlyContinue +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $data = ConvertFrom-csv @" Store,January,February,March,April,May,June @@ -17,12 +19,12 @@ store01,21292,82341,81339,12505,29516,41634 store82,74047,93325,25002,40113,76278,45707 "@ -Export-Excel -InputObject $data -Path $xlfile -TableName RawData -WorksheetName RawData -Export-Excel -InputObject $data -Path $xlfile -TableName TopData -WorksheetName StoresTop10Sales -Export-Excel -InputObject $data -Path $xlfile -TableName Databar -WorksheetName StoresSalesDataBar -Export-Excel -InputObject $data -Path $xlfile -TableName TwoColorScale -WorksheetName StoresSalesTwoColorScale +Export-Excel -InputObject $data -Path $xlSourcefile -TableName RawData -WorksheetName RawData +Export-Excel -InputObject $data -Path $xlSourcefile -TableName TopData -WorksheetName StoresTop10Sales +Export-Excel -InputObject $data -Path $xlSourcefile -TableName Databar -WorksheetName StoresSalesDataBar +Export-Excel -InputObject $data -Path $xlSourcefile -TableName TwoColorScale -WorksheetName StoresSalesTwoColorScale -$xl = Open-ExcelPackage -Path $xlfile +$xl = Open-ExcelPackage -Path $xlSourcefile Set-ExcelRange -Worksheet $xl.StoresTop10Sales -Range $xl.StoresTop10Sales.dimension.address -NumberFormat 'Currency' -AutoSize Set-ExcelRange -Worksheet $xl.StoresSalesDataBar -Range $xl.StoresSalesDataBar.dimension.address -NumberFormat 'Currency' -AutoSize diff --git a/Examples/JoinWorksheet/Join-Worksheet.sample.ps1 b/Examples/JoinWorksheet/Join-Worksheet.sample.ps1 index 1da18c4..6ba2f2e 100644 --- a/Examples/JoinWorksheet/Join-Worksheet.sample.ps1 +++ b/Examples/JoinWorksheet/Join-Worksheet.sample.ps1 @@ -1,8 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} #Get rid of pre-exisiting sheet -$path = "$Env:TEMP\test.xlsx" -remove-item -Path $path -ErrorAction SilentlyContinue +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore #Create simple pages for 3 stores with product ID, Product Name, quanity price and total @@ -13,7 +14,7 @@ ID,Product,Quantity,Price,Total 12003,Saw,12,15.37,184.44 12010,Drill,20,8,160 12011,Crowbar,7,23.48,164.36 -"@ | ConvertFrom-Csv| Export-Excel -Path $path -WorkSheetname Oxford +"@ | ConvertFrom-Csv| Export-Excel -Path $xlSourcefile -WorkSheetname Oxford @" ID,Product,Quantity,Price,Total @@ -22,7 +23,7 @@ ID,Product,Quantity,Price,Total 12003,Saw,10,15.37,153.70 12010,Drill,10,8,80 12012,Pliers,2,14.99,29.98 -"@ | ConvertFrom-Csv| Export-Excel -Path $path -WorkSheetname Abingdon +"@ | ConvertFrom-Csv| Export-Excel -Path $xlSourcefile -WorkSheetname Abingdon @" @@ -31,7 +32,7 @@ ID,Product,Quantity,Price,Total 12002,Hammer,2,12.10,24.20 12010,Drill,11,8,88 12012,Pliers,3,14.99,44.97 -"@ | ConvertFrom-Csv| Export-Excel -Path $path -WorkSheetname Banbury +"@ | ConvertFrom-Csv| Export-Excel -Path $xlSourcefile -WorkSheetname Banbury #define a pivot table with a chart to show a sales by store, broken down by product $ptdef = New-PivotTableDefinition -PivotTableName "Summary" -PivotRows "Store" -PivotColumns "Product" -PivotData @{"Total"="SUM"} -IncludePivotChart -ChartTitle "Sales Breakdown" -ChartType ColumnStacked -ChartColumn 10 @@ -42,4 +43,4 @@ $ptdef = New-PivotTableDefinition -PivotTableName "Summary" -PivotRows "Store" - #Put in a title and freeze to top of the sheet including title and colmun headings #Add the Pivot table. #Show the result -Join-Worksheet -Path $path -WorkSheetName "Total" -Clearsheet -FromLabel "Store" -TableName "Combined" -TableStyle Light1 -AutoSize -BoldTopRow -FreezePane 2,1 -Title "Store Sales Summary" -TitleBold -TitleSize 14 -PivotTableDefinition $ptdef -show +Join-Worksheet -Path $xlSourcefile -WorkSheetName "Total" -Clearsheet -FromLabel "Store" -TableName "Combined" -TableStyle Light1 -AutoSize -BoldTopRow -FreezePane 2,1 -Title "Store Sales Summary" -TitleBold -TitleSize 14 -PivotTableDefinition $ptdef -show diff --git a/Examples/JoinWorksheet/Join-worksheet-blocks.sample.ps1 b/Examples/JoinWorksheet/Join-worksheet-blocks.sample.ps1 index 91be30c..66848c8 100644 --- a/Examples/JoinWorksheet/Join-worksheet-blocks.sample.ps1 +++ b/Examples/JoinWorksheet/Join-worksheet-blocks.sample.ps1 @@ -1,14 +1,17 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$path = "$env:TEMP\Test.xlsx" -Remove-item -Path $path -ErrorAction SilentlyContinue +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore + #Export disk volume, and Network adapter to their own sheets. Get-CimInstance -ClassName Win32_LogicalDisk | Select-Object -Property DeviceId,VolumeName, Size,Freespace | - Export-Excel -Path $path -WorkSheetname Volumes -NumberFormat "0,000" + Export-Excel -Path $xlSourcefile -WorkSheetname Volumes -NumberFormat "0,000" Get-NetAdapter | Select-Object -Property Name,InterfaceDescription,MacAddress,LinkSpeed | - Export-Excel -Path $path -WorkSheetname NetAdapters + Export-Excel -Path $xlSourcefile -WorkSheetname NetAdapters #Create a summary page with a title of Summary, label the blocks with the name of the sheet they came from and hide the source sheets -Join-Worksheet -Path $path -HideSource -WorkSheetName Summary -NoHeader -LabelBlocks -AutoSize -Title "Summary" -TitleBold -TitleSize 22 -show +Join-Worksheet -Path $xlSourcefile -HideSource -WorkSheetName Summary -NoHeader -LabelBlocks -AutoSize -Title "Summary" -TitleBold -TitleSize 22 -show diff --git a/Examples/PivotTable/TableAndPivotTable.ps1 b/Examples/PivotTable/TableAndPivotTable.ps1 index 310fc8c..468d247 100644 --- a/Examples/PivotTable/TableAndPivotTable.ps1 +++ b/Examples/PivotTable/TableAndPivotTable.ps1 @@ -1,5 +1,9 @@ -$path = "$Env:TEMP\test.xlsx" -remove-item -path $path -ErrorAction SilentlyContinue +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} + +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore #Export some sales data to Excel, format it as a table and put a data-bar in. For this example we won't create the pivot table during the export $excel = ConvertFrom-Csv @" @@ -10,7 +14,7 @@ Banana, London , 300, 200 Orange, Paris, 600, 500 Banana, Paris, 300, 200 Apple, New York, 1200,700 -"@ | Export-Excel -PassThru -Path $path -TableStyle Medium13 -tablename "RawData" -ConditionalFormat @{Range="C2:C7"; DataBarColor="Green"} +"@ | Export-Excel -PassThru -Path $xlSourcefile -TableStyle Medium13 -tablename "RawData" -ConditionalFormat @{Range="C2:C7"; DataBarColor="Green"} #Add a pivot table, specify its address to put it on the same sheet, use the data that was just exported set the table style and number format. #Use the "City" for the row names, and "Product" for the columnnames, and sum both the gross and net values for each City/Product combination; add grand totals to rows and columns.