From 8a209635777dc5d6637b5930fae8db0b59903159 Mon Sep 17 00:00:00 2001 From: MikeyBronowski Date: Wed, 1 Jul 2020 22:04:37 +0200 Subject: [PATCH] Standardising examples --- Examples/AddWorkSheet/AddMultiWorkSheet.ps1 | 4 +- Examples/AddWorkSheet/AddWorkSheet.ps1 | 5 ++- Examples/Charts/ChartAndTrendlines.ps1 | 9 ++-- Examples/Charts/MultiSeries.ps1 | 7 ++- Examples/Charts/MultiSeries1.ps1 | 9 ++-- Examples/Charts/MultipleCharts.ps1 | 7 ++- Examples/Charts/NumberOfVisitors.ps1 | 4 +- Examples/Charts/plot.ps1 | 8 ++-- .../ConditionalFormatting/ConditionalText.ps1 | 8 ++-- .../ConditionalFormatting/ContainsBlanks.ps1 | 8 ++-- Examples/ConditionalFormatting/Databar.ps1 | 8 ++-- .../FormatCalculations.ps1 | 13 +++--- Examples/ConditionalFormatting/GenDates.ps1 | 2 + Examples/ConditionalFormatting/GetProcess.ps1 | 7 ++- .../Highlight-Last7Days.ps1 | 9 ++-- .../Highlight-LastMonth.ps1 | 9 ++-- .../Highlight-LastWeek.ps1 | 9 ++-- .../Highlight-NextMonth.ps1 | 9 ++-- .../Highlight-NextWeek.ps1 | 9 ++-- .../Highlight-ThisMonth.ps1 | 9 ++-- .../Highlight-ThisWeek.ps1 | 9 ++-- .../ConditionalFormatting/Highlight-Today.ps1 | 9 ++-- .../Highlight-Tomorrow.ps1 | 9 ++-- .../Highlight-Yesterday.ps1 | 9 ++-- .../HighlightDuplicates.ps1 | 9 ++-- .../MonthlyTemperatuesDatabar.ps1 | 7 ++- .../ConditionalFormatting/RangeFormatting.ps1 | 8 ++-- .../SalesReportWithDatabar.ps1 | 7 ++- .../ConditionalFormatting/TextComparisons.ps1 | 44 ++++++++++--------- .../Top10-DataBar-TwoColorScale.ps1 | 4 +- Examples/CustomReporting/CustomReport.ps1 | 10 +++-- Examples/ExcelBuiltIns/DSUM.ps1 | 9 ++-- Examples/ExcelBuiltIns/VLOOKUP.ps1 | 14 +++--- .../MutipleValidations.ps1 | 8 ++-- .../tryExportMultipleExcelSheets.ps1 | 8 ++-- Examples/Fibonacci/ShowFibonacci.ps1 | 8 ++-- .../ApplyFormatInScriptBlock.ps1 | 7 ++- Examples/FormatCellStyles/ApplyStyle.ps1 | 4 +- .../FormatCellStyles/PassInScriptBlock.ps1 | 8 ++-- Examples/Grouping/GroupDate.ps1 | 11 +++-- Examples/Grouping/GroupNumeric.ps1 | 9 ++-- Examples/Grouping/TimestampBucket.ps1 | 9 ++-- Examples/HyperLinks/Races.ps1 | 1 + .../JoinWorksheet/Join-Worksheet.sample.ps1 | 4 +- .../Join-worksheet-blocks.sample.ps1 | 1 + Examples/JoinWorksheet/JoinSalesData.ps1 | 9 ++-- Examples/MergeWorkSheet/MergeCSV.ps1 | 9 ++-- .../Merge_2_Servers_Services.ps1 | 2 + .../Merge_3_Servers_Services.ps1 | 2 + .../MortgageCalculator/MortgageCalculator.ps1 | 2 +- 50 files changed, 249 insertions(+), 154 deletions(-) diff --git a/Examples/AddWorkSheet/AddMultiWorkSheet.ps1 b/Examples/AddWorkSheet/AddMultiWorkSheet.ps1 index b16a91b..4a15bb3 100644 --- a/Examples/AddWorkSheet/AddMultiWorkSheet.ps1 +++ b/Examples/AddWorkSheet/AddMultiWorkSheet.ps1 @@ -1,8 +1,8 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$xlSourcefile = "$env:TEMP\Source.xlsx" +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" Write-Verbose -Verbose -Message "Save location: $xlSourcefile" - Remove-Item $xlSourcefile -ErrorAction Ignore #Put some simple data in a worksheet and Get an excel package object to represent the file diff --git a/Examples/AddWorkSheet/AddWorkSheet.ps1 b/Examples/AddWorkSheet/AddWorkSheet.ps1 index dc7fbbf..f22c946 100644 --- a/Examples/AddWorkSheet/AddWorkSheet.ps1 +++ b/Examples/AddWorkSheet/AddWorkSheet.ps1 @@ -1,7 +1,8 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$xlSourcefile = "$env:TEMP\Source.xlsx" - +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" Remove-Item $xlSourcefile -ErrorAction Ignore #Put some simple data in a worksheet and Get an excel package object to represent the file diff --git a/Examples/Charts/ChartAndTrendlines.ps1 b/Examples/Charts/ChartAndTrendlines.ps1 index 7e2d41d..f80b4cc 100644 --- a/Examples/Charts/ChartAndTrendlines.ps1 +++ b/Examples/Charts/ChartAndTrendlines.ps1 @@ -1,7 +1,10 @@ # Creates a worksheet, addes a chart and then a Linear trendline +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$xlfile = "$env:TEMP\trendLine.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 @" Region,Item,TotalSold @@ -18,4 +21,4 @@ South,avocado,73 "@ $cd = New-ExcelChartDefinition -XRange Region -YRange TotalSold -ChartType ColumnClustered -ChartTrendLine Linear -$data | Export-Excel $xlfile -ExcelChartDefinition $cd -AutoNameRange -Show +$data | Export-Excel $xlSourcefile -ExcelChartDefinition $cd -AutoNameRange -Show diff --git a/Examples/Charts/MultiSeries.ps1 b/Examples/Charts/MultiSeries.ps1 index ff3fdfb..1f980a9 100644 --- a/Examples/Charts/MultiSeries.ps1 +++ b/Examples/Charts/MultiSeries.ps1 @@ -1,6 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -Remove-Item temp.xlsx -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $data = Invoke-Sum -data (Get-Process) -dimension Company -measure Handles, PM, VirtualMemorySize @@ -11,4 +14,4 @@ $c = New-ExcelChartDefinition -Title "ProcessStats" ` -SeriesHeader "PM","VM" $data | - Export-Excel -Path temp.xlsx -AutoSize -TableName Processes -ExcelChartDefinition $c -Show + Export-Excel -Path $xlSourcefile -AutoSize -TableName Processes -ExcelChartDefinition $c -Show diff --git a/Examples/Charts/MultiSeries1.ps1 b/Examples/Charts/MultiSeries1.ps1 index e727ffc..46f78da 100644 --- a/Examples/Charts/MultiSeries1.ps1 +++ b/Examples/Charts/MultiSeries1.ps1 @@ -1,6 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -Remove-Item temp.xlsx -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $data = @" A,B,C,Date @@ -15,5 +18,5 @@ $c = New-ExcelChartDefinition -Title Impressions ` -SeriesHeader 'B data','A data' ` -Row 0 -Column 0 -$data | ConvertFrom-Csv | Export-Excel -path temp.xlsx -AutoSize -TableName Impressions -Export-Excel -path temp.xlsx -worksheetName chartPage -ExcelChartDefinition $c -show +$data | ConvertFrom-Csv | Export-Excel -path $xlSourcefile -AutoSize -TableName Impressions +Export-Excel -path $xlSourcefile -worksheetName chartPage -ExcelChartDefinition $c -show diff --git a/Examples/Charts/MultipleCharts.ps1 b/Examples/Charts/MultipleCharts.ps1 index 82f5ad0..1041001 100644 --- a/Examples/Charts/MultipleCharts.ps1 +++ b/Examples/Charts/MultipleCharts.ps1 @@ -1,6 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -Remove-Item -Path Tools.xlsx +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $data = @" ID,Product,Quantity,Price,Total @@ -16,4 +19,4 @@ $c2 = New-ExcelChartDefinition -YRange "Total "-XRange "Product" -Title "Total $c3 = New-ExcelChartDefinition -YRange "Quantity"-XRange "Product" -Title "Sales volume" -NoLegend -Height 225 -Row 15 $data | ConvertFrom-Csv | - Export-Excel -Path "Tools.xlsx" -AutoFilter -AutoNameRange -AutoSize -ExcelChartDefinition $c1,$c2,$c3 -Show \ No newline at end of file + Export-Excel -Path $xlSourcefile -AutoFilter -AutoNameRange -AutoSize -ExcelChartDefinition $c1,$c2,$c3 -Show \ No newline at end of file diff --git a/Examples/Charts/NumberOfVisitors.ps1 b/Examples/Charts/NumberOfVisitors.ps1 index b3c8517..b4c7e3f 100644 --- a/Examples/Charts/NumberOfVisitors.ps1 +++ b/Examples/Charts/NumberOfVisitors.ps1 @@ -1,4 +1,6 @@ -$xlfile = "$env:TEMP\visitors.xlsx" +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} + +$xlfile = "$env:TEMP\visitors.xlsx" Remove-Item $xlfile -ErrorAction SilentlyContinue $data = ConvertFrom-Csv @" diff --git a/Examples/Charts/plot.ps1 b/Examples/Charts/plot.ps1 index 839a816..afcb7a9 100644 --- a/Examples/Charts/plot.ps1 +++ b/Examples/Charts/plot.ps1 @@ -10,8 +10,10 @@ function plot { $minx=[math]::Round($minx,1) $maxx=[math]::Round($maxx,1) - $file = 'C:\temp\plot.xlsx' - Remove-Item $file -ErrorAction Ignore + #Get rid of pre-exisiting sheet + $xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" + Write-Verbose -Verbose -Message "Save location: $xlSourcefile" + Remove-Item $xlSourcefile -ErrorAction Ignore # $c = New-ExcelChart -XRange X -YRange Y -ChartType Line -NoLegend -Title Plot -Column 2 -ColumnOffSetPixels 35 @@ -20,7 +22,7 @@ function plot { X=$i.ToString("N1") Y=(&$f $i) } - }) | Export-Excel $file -Show -AutoNameRange -LineChart -NoLegend #-ExcelChartDefinition $c + }) | Export-Excel $xlSourcefile -Show -AutoNameRange -LineChart -NoLegend #-ExcelChartDefinition $c } function pi {[math]::pi} diff --git a/Examples/ConditionalFormatting/ConditionalText.ps1 b/Examples/ConditionalFormatting/ConditionalText.ps1 index 8a9b9ab..da10b1e 100644 --- a/Examples/ConditionalFormatting/ConditionalText.ps1 +++ b/Examples/ConditionalFormatting/ConditionalText.ps1 @@ -1,11 +1,13 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$file = "$env:temp\conditionalTextFormatting.xlsx" -Remove-Item $file -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore Get-Service | Select-Object Status, Name, DisplayName, ServiceName | - Export-Excel $file -Show -AutoSize -AutoFilter -ConditionalText $( + Export-Excel $xlSourcefile -Show -AutoSize -AutoFilter -ConditionalText $( New-ConditionalText stop #Stop is the condition value, the rule is defaults to 'Contains text' and the default Colors are used New-ConditionalText runn darkblue cyan #runn is the condition value, the rule is defaults to 'Contains text'; the foregroundColur is darkblue and the background is cyan New-ConditionalText -ConditionalType EndsWith svc wheat green #the rule here is 'Ends with' and the value is 'svc' the forground is wheat and the background dark green diff --git a/Examples/ConditionalFormatting/ContainsBlanks.ps1 b/Examples/ConditionalFormatting/ContainsBlanks.ps1 index bbbde4b..0590ac9 100644 --- a/Examples/ConditionalFormatting/ContainsBlanks.ps1 +++ b/Examples/ConditionalFormatting/ContainsBlanks.ps1 @@ -12,8 +12,10 @@ $data = $( New-PSItem g h i ) -$file ="$env:temp\testblanks.xlsx" +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore -Remove-Item $file -ErrorAction Ignore #use the conditional format definition created above -$data | Export-Excel $file -show -ConditionalText $ContainsBlanks \ No newline at end of file +$data | Export-Excel $xlSourcefile -show -ConditionalText $ContainsBlanks \ No newline at end of file diff --git a/Examples/ConditionalFormatting/Databar.ps1 b/Examples/ConditionalFormatting/Databar.ps1 index d5292f5..911db7d 100644 --- a/Examples/ConditionalFormatting/Databar.ps1 +++ b/Examples/ConditionalFormatting/Databar.ps1 @@ -1,12 +1,14 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$path = "$env:temp\test.xlsx" -Remove-Item -Path $path -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore #Export processes, and get an ExcelPackage object representing the file. $excel = Get-Process | Select-Object -Property Name,Company,Handles,CPU,PM,NPM,WS | - Export-Excel -Path $path -ClearSheet -WorkSheetname "Processes" -PassThru + Export-Excel -Path $xlSourcefile -ClearSheet -WorkSheetname "Processes" -PassThru $sheet = $excel.Workbook.Worksheets["Processes"] diff --git a/Examples/ConditionalFormatting/FormatCalculations.ps1 b/Examples/ConditionalFormatting/FormatCalculations.ps1 index 3b80bb1..a275a5f 100644 --- a/Examples/ConditionalFormatting/FormatCalculations.ps1 +++ b/Examples/ConditionalFormatting/FormatCalculations.ps1 @@ -1,8 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = "$env:TEMP\testExport.xlsx" - -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $data = $( @@ -25,6 +26,6 @@ $data = $( # the syntax is used is Export-excel -ConditionalText (New-Conditional text ) -#$data | Export-Excel $f -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType AboveAverage) -$data | Export-Excel $f -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType BelowAverage) -#$data | Export-Excel $f -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType TopPercent) +#$data | Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType AboveAverage) +$data | Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType BelowAverage) +#$data | Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType TopPercent) diff --git a/Examples/ConditionalFormatting/GenDates.ps1 b/Examples/ConditionalFormatting/GenDates.ps1 index 6a32e36..e5e77d9 100644 --- a/Examples/ConditionalFormatting/GenDates.ps1 +++ b/Examples/ConditionalFormatting/GenDates.ps1 @@ -1,3 +1,5 @@ +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} + function Get-DateOffset { param($days=0) diff --git a/Examples/ConditionalFormatting/GetProcess.ps1 b/Examples/ConditionalFormatting/GetProcess.ps1 index 860d130..036c85f 100644 --- a/Examples/ConditionalFormatting/GetProcess.ps1 +++ b/Examples/ConditionalFormatting/GetProcess.ps1 @@ -1,12 +1,15 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -Remove-Item "$env:TEMP\testExport.xlsx" -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore Get-Process | Where-Object Company | Select-Object Company, Name, PM, Handles, *mem* | #This example creates a 3 Icon set for the values in the "PM column, and Highlights company names (anywhere in the data) with different colors - Export-Excel "$env:TEMP\testExport.xlsx" -Show -AutoSize -AutoNameRange ` + Export-Excel -Path $xlSourcefile -Show -AutoSize -AutoNameRange ` -ConditionalFormat $( New-ConditionalFormattingIconSet -Range "C:C" ` -ConditionalFormat ThreeIconSet -IconType Arrows diff --git a/Examples/ConditionalFormatting/Highlight-Last7Days.ps1 b/Examples/ConditionalFormatting/Highlight-Last7Days.ps1 index 005f17a..d8315fe 100644 --- a/Examples/ConditionalFormatting/Highlight-Last7Days.ps1 +++ b/Examples/ConditionalFormatting/Highlight-Last7Days.ps1 @@ -1,10 +1,11 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = ".\testExport.xlsx" - -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore .\GenDates.ps1 | - Export-Excel $f -Show -AutoSize -ConditionalText $( + Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText $( New-ConditionalText -ConditionalType Last7Days ) diff --git a/Examples/ConditionalFormatting/Highlight-LastMonth.ps1 b/Examples/ConditionalFormatting/Highlight-LastMonth.ps1 index fe837b4..1147bdf 100644 --- a/Examples/ConditionalFormatting/Highlight-LastMonth.ps1 +++ b/Examples/ConditionalFormatting/Highlight-LastMonth.ps1 @@ -1,10 +1,11 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = ".\testExport.xlsx" - -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore .\GenDates.ps1 | - Export-Excel $f -Show -AutoSize -ConditionalText $( + Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText $( New-ConditionalText -ConditionalType LastMonth ) diff --git a/Examples/ConditionalFormatting/Highlight-LastWeek.ps1 b/Examples/ConditionalFormatting/Highlight-LastWeek.ps1 index 7877296..c730304 100644 --- a/Examples/ConditionalFormatting/Highlight-LastWeek.ps1 +++ b/Examples/ConditionalFormatting/Highlight-LastWeek.ps1 @@ -1,10 +1,11 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = ".\testExport.xlsx" - -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore .\GenDates.ps1 | - Export-Excel $f -Show -AutoSize -ConditionalText $( + Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText $( New-ConditionalText -ConditionalType LastWeek ) diff --git a/Examples/ConditionalFormatting/Highlight-NextMonth.ps1 b/Examples/ConditionalFormatting/Highlight-NextMonth.ps1 index ca8285a..25e1db3 100644 --- a/Examples/ConditionalFormatting/Highlight-NextMonth.ps1 +++ b/Examples/ConditionalFormatting/Highlight-NextMonth.ps1 @@ -1,10 +1,11 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = ".\testExport.xlsx" - -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore .\GenDates.ps1 | - Export-Excel $f -Show -AutoSize -ConditionalText $( + Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText $( New-ConditionalText -ConditionalType NextMonth ) diff --git a/Examples/ConditionalFormatting/Highlight-NextWeek.ps1 b/Examples/ConditionalFormatting/Highlight-NextWeek.ps1 index 5930faa..88cf7cd 100644 --- a/Examples/ConditionalFormatting/Highlight-NextWeek.ps1 +++ b/Examples/ConditionalFormatting/Highlight-NextWeek.ps1 @@ -1,10 +1,11 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = ".\testExport.xlsx" - -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore .\GenDates.ps1 | - Export-Excel $f -Show -AutoSize -ConditionalText $( + Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText $( New-ConditionalText -ConditionalType NextWeek ) diff --git a/Examples/ConditionalFormatting/Highlight-ThisMonth.ps1 b/Examples/ConditionalFormatting/Highlight-ThisMonth.ps1 index e3ddb87..2ae7079 100644 --- a/Examples/ConditionalFormatting/Highlight-ThisMonth.ps1 +++ b/Examples/ConditionalFormatting/Highlight-ThisMonth.ps1 @@ -1,10 +1,11 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = ".\testExport.xlsx" - -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore .\GenDates.ps1 | - Export-Excel $f -Show -AutoSize -ConditionalText $( + Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText $( New-ConditionalText -ConditionalType ThisMonth ) diff --git a/Examples/ConditionalFormatting/Highlight-ThisWeek.ps1 b/Examples/ConditionalFormatting/Highlight-ThisWeek.ps1 index da9f46a..37ada65 100644 --- a/Examples/ConditionalFormatting/Highlight-ThisWeek.ps1 +++ b/Examples/ConditionalFormatting/Highlight-ThisWeek.ps1 @@ -1,10 +1,11 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = ".\testExport.xlsx" - -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore .\GenDates.ps1 | - Export-Excel $f -Show -AutoSize -ConditionalText $( + Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText $( New-ConditionalText -ConditionalType ThisWeek ) diff --git a/Examples/ConditionalFormatting/Highlight-Today.ps1 b/Examples/ConditionalFormatting/Highlight-Today.ps1 index 58df813..c009578 100644 --- a/Examples/ConditionalFormatting/Highlight-Today.ps1 +++ b/Examples/ConditionalFormatting/Highlight-Today.ps1 @@ -1,10 +1,11 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = ".\testExport.xlsx" - -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore .\GenDates.ps1 | - Export-Excel $f -Show -AutoSize -ConditionalText $( + Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText $( New-ConditionalText -ConditionalType Today ) diff --git a/Examples/ConditionalFormatting/Highlight-Tomorrow.ps1 b/Examples/ConditionalFormatting/Highlight-Tomorrow.ps1 index e6dc9f4..6d9ccea 100644 --- a/Examples/ConditionalFormatting/Highlight-Tomorrow.ps1 +++ b/Examples/ConditionalFormatting/Highlight-Tomorrow.ps1 @@ -1,10 +1,11 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = ".\testExport.xlsx" - -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore .\GenDates.ps1 | - Export-Excel $f -Show -AutoSize -ConditionalText $( + Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText $( New-ConditionalText -ConditionalType Tomorrow ) diff --git a/Examples/ConditionalFormatting/Highlight-Yesterday.ps1 b/Examples/ConditionalFormatting/Highlight-Yesterday.ps1 index 0b3f080..f13059c 100644 --- a/Examples/ConditionalFormatting/Highlight-Yesterday.ps1 +++ b/Examples/ConditionalFormatting/Highlight-Yesterday.ps1 @@ -1,10 +1,11 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = ".\testExport.xlsx" - -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore .\GenDates.ps1 | - Export-Excel $f -Show -AutoSize -ConditionalText $( + Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText $( New-ConditionalText -ConditionalType Yesterday ) diff --git a/Examples/ConditionalFormatting/HighlightDuplicates.ps1 b/Examples/ConditionalFormatting/HighlightDuplicates.ps1 index 58bd4c3..8d1629f 100644 --- a/Examples/ConditionalFormatting/HighlightDuplicates.ps1 +++ b/Examples/ConditionalFormatting/HighlightDuplicates.ps1 @@ -1,8 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = ".\testExport.xlsx" - -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $data = $( @@ -22,4 +23,4 @@ $data = $( New-PSItem SouthWest 11 ) -$data | Export-Excel $f -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType DuplicateValues) \ No newline at end of file +$data | Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType DuplicateValues) \ No newline at end of file diff --git a/Examples/ConditionalFormatting/MonthlyTemperatuesDatabar.ps1 b/Examples/ConditionalFormatting/MonthlyTemperatuesDatabar.ps1 index 3c374dd..a2606bb 100644 --- a/Examples/ConditionalFormatting/MonthlyTemperatuesDatabar.ps1 +++ b/Examples/ConditionalFormatting/MonthlyTemperatuesDatabar.ps1 @@ -1,6 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -Remove-Item -Path .\test.xlsx -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $excel = @" Month,New York City,Austin Texas,Portland Oregon @@ -17,7 +20,7 @@ Oct,65,82,63 Nov,54,71,52 Dec,44,63,46 "@ | ConvertFrom-csv | - Export-Excel -Path .\test.xlsx -WorkSheetname Sheet1 -AutoNameRange -AutoSize -Title "Monthly Temperatures" -PassThru + Export-Excel -Path $xlSourcefile -WorkSheetname Sheet1 -AutoNameRange -AutoSize -Title "Monthly Temperatures" -PassThru $sheet = $excel.Workbook.Worksheets["Sheet1"] Add-ConditionalFormatting -Worksheet $sheet -Range "B1:D14" -DataBarColor CornflowerBlue diff --git a/Examples/ConditionalFormatting/RangeFormatting.ps1 b/Examples/ConditionalFormatting/RangeFormatting.ps1 index 05c65b4..2de1767 100644 --- a/Examples/ConditionalFormatting/RangeFormatting.ps1 +++ b/Examples/ConditionalFormatting/RangeFormatting.ps1 @@ -1,7 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = ".\testExport.xlsx" -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore function Get-DateOffset ($days=0) { (Get-Date).AddDays($days).ToShortDateString() @@ -13,7 +15,7 @@ $( New-PSItem (Get-DateOffset -10) (Get-DateOffset -1) ) | - Export-Excel $f -Show -AutoSize -AutoNameRange -ConditionalText $( + Export-Excel $xlSourcefile -Show -AutoSize -AutoNameRange -ConditionalText $( New-ConditionalText -Range Start -ConditionalType Yesterday -ConditionalTextColor Red New-ConditionalText -Range End -ConditionalType Yesterday -BackgroundColor Blue -ConditionalTextColor Red ) \ No newline at end of file diff --git a/Examples/ConditionalFormatting/SalesReportWithDatabar.ps1 b/Examples/ConditionalFormatting/SalesReportWithDatabar.ps1 index 35cc92f..ef94be0 100644 --- a/Examples/ConditionalFormatting/SalesReportWithDatabar.ps1 +++ b/Examples/ConditionalFormatting/SalesReportWithDatabar.ps1 @@ -1,6 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -Remove-Item -Path .\test.xlsx -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $excel = @" Month,Sales @@ -11,7 +14,7 @@ Apr,952 May,770 Jun,621 "@ | ConvertFrom-csv | - Export-Excel -Path .\test.xlsx -WorkSheetname Sheet1 -AutoNameRange -PassThru + Export-Excel -Path $xlSourcefile -WorkSheetname Sheet1 -AutoNameRange -PassThru $sheet = $excel.Workbook.Worksheets["Sheet1"] Add-ConditionalFormatting -Worksheet $sheet -Range "B1:B7" -DataBarColor LawnGreen diff --git a/Examples/ConditionalFormatting/TextComparisons.ps1 b/Examples/ConditionalFormatting/TextComparisons.ps1 index 729f38f..55837f2 100644 --- a/Examples/ConditionalFormatting/TextComparisons.ps1 +++ b/Examples/ConditionalFormatting/TextComparisons.ps1 @@ -1,25 +1,29 @@ -try {Import-Module ..\..\ImportExcel.psd1 -Force} catch {throw ; return} + try {Import-Module ..\..\ImportExcel.psd1 -Force} catch {throw ; return} -$data = $( - New-PSItem 100 @('test', 'testx') - New-PSItem 200 - New-PSItem 300 - New-PSItem 400 - New-PSItem 500 -) + $data = $( + New-PSItem 100 @('test', 'testx') + New-PSItem 200 + New-PSItem 300 + New-PSItem 400 + New-PSItem 500 + ) -$file1 = "$env:Temp\tryComparison1.xlsx" -$file2 = "$env:Temp\tryComparison2.xlsx" + #Get rid of pre-exisiting sheet + $xlSourcefile1 = "$env:TEMP\ImportExcelExample1.xlsx" + $xlSourcefile2 = "$env:TEMP\ImportExcelExample2.xlsx" -Remove-Item -Path $file1 -ErrorAction Ignore -Remove-Item -Path $file2 -ErrorAction Ignore + Write-Verbose -Verbose -Message "Save location: $xlSourcefile1" + Write-Verbose -Verbose -Message "Save location: $xlSourcefile2" -$data | Export-Excel $file1 -Show -ConditionalText $( - New-ConditionalText -ConditionalType GreaterThan 300 - New-ConditionalText -ConditionalType LessThan 300 -BackgroundColor cyan -) + Remove-Item $xlSourcefile1 -ErrorAction Ignore + Remove-Item $xlSourcefile2 -ErrorAction Ignore -$data | Export-Excel $file2 -Show -ConditionalText $( - New-ConditionalText -ConditionalType GreaterThanOrEqual 275 - New-ConditionalText -ConditionalType LessThanOrEqual 250 -BackgroundColor cyan -) + $data | Export-Excel $xlSourcefile1 -Show -ConditionalText $( + New-ConditionalText -ConditionalType GreaterThan 300 + New-ConditionalText -ConditionalType LessThan 300 -BackgroundColor cyan + ) + + $data | Export-Excel $xlSourcefile2 -Show -ConditionalText $( + New-ConditionalText -ConditionalType GreaterThanOrEqual 275 + New-ConditionalText -ConditionalType LessThanOrEqual 250 -BackgroundColor cyan + ) diff --git a/Examples/ConditionalFormatting/Top10-DataBar-TwoColorScale.ps1 b/Examples/ConditionalFormatting/Top10-DataBar-TwoColorScale.ps1 index f462549..932b109 100644 --- a/Examples/ConditionalFormatting/Top10-DataBar-TwoColorScale.ps1 +++ b/Examples/ConditionalFormatting/Top10-DataBar-TwoColorScale.ps1 @@ -1,4 +1,6 @@ -$xlfile = "$env:TEMP\test.xlsx" +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} + +$xlfile = "$env:TEMP\test.xlsx" Remove-Item $xlfile -ErrorAction SilentlyContinue $data = ConvertFrom-csv @" diff --git a/Examples/CustomReporting/CustomReport.ps1 b/Examples/CustomReporting/CustomReport.ps1 index 58dffb4..b501819 100644 --- a/Examples/CustomReporting/CustomReport.ps1 +++ b/Examples/CustomReporting/CustomReport.ps1 @@ -1,7 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$f = "$env:temp\dashboard.xlsx" -Remove-Item $f -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $data = @" From,To,RDollars,RPercent,MDollars,MPercent,Revenue,Margin @@ -13,9 +15,9 @@ New York,San Francisco,3221000,.0629,1088000,.04,436,21 New York,Phoneix,2782000,.0723,467000,.10,674,33 "@ | ConvertFrom-Csv -$data | Export-Excel $f -AutoSize +$data | Export-Excel $xlSourcefile -AutoSize -$excel = Open-ExcelPackage $f +$excel = Open-ExcelPackage $xlSourcefile $sheet1 = $excel.Workbook.Worksheets["sheet1"] diff --git a/Examples/ExcelBuiltIns/DSUM.ps1 b/Examples/ExcelBuiltIns/DSUM.ps1 index 26f3839..1e368e1 100644 --- a/Examples/ExcelBuiltIns/DSUM.ps1 +++ b/Examples/ExcelBuiltIns/DSUM.ps1 @@ -1,8 +1,11 @@ # DSUM # Adds the numbers in a field (column) of records in a list or database that match conditions that you specify. +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 @" Color,Date,Sales @@ -14,7 +17,7 @@ Red,1/17/2018,150 Blue,1/17/2018,300 "@ -$xl = Export-Excel -InputObject $data -Path $xlfile -AutoSize -AutoFilter -TableName SalesInfo -AutoNameRange -PassThru +$xl = Export-Excel -InputObject $data -Path $xlSourcefile -AutoSize -AutoFilter -TableName SalesInfo -AutoNameRange -PassThru $databaseAddress = $xl.Sheet1.Dimension.Address Set-Format -Worksheet $xl.Sheet1 -Range C:C -NumberFormat '$##0' diff --git a/Examples/ExcelBuiltIns/VLOOKUP.ps1 b/Examples/ExcelBuiltIns/VLOOKUP.ps1 index a04fecb..139d783 100644 --- a/Examples/ExcelBuiltIns/VLOOKUP.ps1 +++ b/Examples/ExcelBuiltIns/VLOOKUP.ps1 @@ -1,5 +1,9 @@ -$xlfile = "$env:TEMP\test.xlsx" -Remove-Item $xlfile -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 $data = ConvertFrom-Csv @" Fruit,Amount @@ -9,11 +13,11 @@ Bananas,60 Lemons,40 "@ -$xl = Export-Excel -InputObject $data -Path $xlfile -PassThru -AutoSize +$xl = Export-Excel -InputObject $data -Path $xlSourcefile -PassThru -AutoSize Set-ExcelRange -Worksheet $xl.Sheet1 -Range D2 -BackgroundColor LightBlue -Value Apples -$Rows = $xl.Sheet1.Dimension.Rows -Set-ExcelRange -Worksheet $xl.Sheet1 -Range E2 -Formula "=VLookup(D2,A2:B$($Rows),2,FALSE)" +$rows = $xl.Sheet1.Dimension.Rows +Set-ExcelRange -Worksheet $xl.Sheet1 -Range E2 -Formula "=VLookup(D2,A2:B$($rows),2,FALSE)" Close-ExcelPackage $xl -Show \ No newline at end of file diff --git a/Examples/ExcelDataValidation/MutipleValidations.ps1 b/Examples/ExcelDataValidation/MutipleValidations.ps1 index 8b813b7..f5970a5 100644 --- a/Examples/ExcelDataValidation/MutipleValidations.ps1 +++ b/Examples/ExcelDataValidation/MutipleValidations.ps1 @@ -15,8 +15,10 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$path = "$Env:TEMP\DataValidation.xlsx" -Remove-Item $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 $data = ConvertFrom-Csv -InputObject @" ID,Region,Product,Quantity,Price @@ -29,7 +31,7 @@ ID,Region,Product,Quantity,Price # Export the raw data $excelPackage = $Data | - Export-Excel -WorksheetName "Sales" -Path $path -PassThru + Export-Excel -WorksheetName "Sales" -Path $xlSourcefile -PassThru # Creates a sheet with data that will be used in a validation rule $excelPackage = @('Chisel', 'Crowbar', 'Drill', 'Hammer', 'Nails', 'Saw', 'Screwdriver', 'Wrench') | diff --git a/Examples/Experimental/tryExportMultipleExcelSheets.ps1 b/Examples/Experimental/tryExportMultipleExcelSheets.ps1 index 7ccbd00..922dd00 100644 --- a/Examples/Experimental/tryExportMultipleExcelSheets.ps1 +++ b/Examples/Experimental/tryExportMultipleExcelSheets.ps1 @@ -1,7 +1,9 @@ . "$PSScriptRoot\Export-MultipleExcelSheets.ps1" -$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 $p = Get-Process @@ -14,4 +16,4 @@ $InfoMap = @{ WillNotGetExported = "Hello World" } -Export-MultipleExcelSheets -Path $xlfile -InfoMap $InfoMap -Show -AutoSize \ No newline at end of file +Export-MultipleExcelSheets -Path $xlSourcefile -InfoMap $InfoMap -Show -AutoSize \ No newline at end of file diff --git a/Examples/Fibonacci/ShowFibonacci.ps1 b/Examples/Fibonacci/ShowFibonacci.ps1 index eab3a94..4948db6 100644 --- a/Examples/Fibonacci/ShowFibonacci.ps1 +++ b/Examples/Fibonacci/ShowFibonacci.ps1 @@ -2,8 +2,10 @@ param ($fibonacciDigits=10) try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$file = "fib.xlsx" -Remove-Item "fib.xlsx" -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $( New-PSItem 0 @@ -15,4 +17,4 @@ $( New-PSItem ('=a{0}+a{1}' -f ($_+1),$_) } ) -) | Export-Excel $file -Show +) | Export-Excel $xlSourcefile -Show diff --git a/Examples/FormatCellStyles/ApplyFormatInScriptBlock.ps1 b/Examples/FormatCellStyles/ApplyFormatInScriptBlock.ps1 index 10e1f41..9dca551 100644 --- a/Examples/FormatCellStyles/ApplyFormatInScriptBlock.ps1 +++ b/Examples/FormatCellStyles/ApplyFormatInScriptBlock.ps1 @@ -1,10 +1,13 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$xlfile = "$env:temp\testFmt.xlsx" +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore Get-Process | Select-Object Company,Handles,PM, NPM| - Export-Excel $xlfile -Show -AutoSize -CellStyleSB { + Export-Excel $xlSourcefile -Show -AutoSize -CellStyleSB { param( $workSheet, $totalRows, diff --git a/Examples/FormatCellStyles/ApplyStyle.ps1 b/Examples/FormatCellStyles/ApplyStyle.ps1 index ce483d2..8ec6708 100644 --- a/Examples/FormatCellStyles/ApplyStyle.ps1 +++ b/Examples/FormatCellStyles/ApplyStyle.ps1 @@ -1,4 +1,6 @@ -$data = ConvertFrom-Csv @' +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} + +$data = ConvertFrom-Csv @' Item,Quantity,Price,Total Cost Footballs,9,21.95,197.55 Cones,36,7.99,287.64 diff --git a/Examples/FormatCellStyles/PassInScriptBlock.ps1 b/Examples/FormatCellStyles/PassInScriptBlock.ps1 index fca55bc..d043ff3 100644 --- a/Examples/FormatCellStyles/PassInScriptBlock.ps1 +++ b/Examples/FormatCellStyles/PassInScriptBlock.ps1 @@ -1,7 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$xlfile = "$env:temp\testFmt.xlsx" -Remove-Item $xlfile -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $RandomStyle = { param( @@ -17,4 +19,4 @@ $RandomStyle = { Get-Process | Select-Object Company,Handles,PM, NPM| - Export-Excel $xlfile -Show -AutoSize -CellStyleSB $RandomStyle + Export-Excel $xlSourcefile -Show -AutoSize -CellStyleSB $RandomStyle diff --git a/Examples/Grouping/GroupDate.ps1 b/Examples/Grouping/GroupDate.ps1 index c562bbe..9429c1c 100644 --- a/Examples/Grouping/GroupDate.ps1 +++ b/Examples/Grouping/GroupDate.ps1 @@ -1,10 +1,13 @@ -$xlfile = "$env:TEMP\Points.xlsx" +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -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 $PivotTableDefinition = New-PivotTableDefinition -Activate -PivotTableName Points ` -PivotRows Driver, Date -PivotData @{Points = "SUM"} -GroupDateRow Date -GroupDatePart Years, Months Import-Csv "$PSScriptRoot\First10Races.csv" | - Select-Object Race, @{n = "Date"; e = {[datetime]::ParseExact($_.date, "dd/MM/yyyy", (Get-Culture))}}, FinishPosition, Driver, GridPosition, Team, Points | - Export-Excel $xlfile -Show -AutoSize -PivotTableDefinition $PivotTableDefinition \ No newline at end of file + Select-Object Race, @{n = "Date"; e = {[datetime]::ParseExact($_.date, "dd/MM/yyyy", (Get-Culture))}}, FinishPosition, Driver, GridPosition, Team, Points | + Export-Excel $xlSourcefile -Show -AutoSize -PivotTableDefinition $PivotTableDefinition \ No newline at end of file diff --git a/Examples/Grouping/GroupNumeric.ps1 b/Examples/Grouping/GroupNumeric.ps1 index 1abb99f..5d743e4 100644 --- a/Examples/Grouping/GroupNumeric.ps1 +++ b/Examples/Grouping/GroupNumeric.ps1 @@ -1,10 +1,13 @@ -$xlfile = "$env:TEMP\Places.xlsx" +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -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 $PivotTableDefinition = New-PivotTableDefinition -Activate -PivotTableName Places ` -PivotRows Driver, FinishPosition -PivotData @{Date = "Count"} -GroupNumericRow FinishPosition -GroupNumericMin 1 -GroupNumericMax 25 -GroupNumericInterval 3 Import-Csv "$PSScriptRoot\First10Races.csv" | Select-Object Race, @{n = "Date"; e = {[datetime]::ParseExact($_.date, "dd/MM/yyyy", (Get-Culture))}}, FinishPosition, Driver, GridPosition, Team, Points | - Export-Excel $xlfile -Show -AutoSize -PivotTableDefinition $PivotTableDefinition \ No newline at end of file + Export-Excel $xlSourcefile -Show -AutoSize -PivotTableDefinition $PivotTableDefinition \ No newline at end of file diff --git a/Examples/Grouping/TimestampBucket.ps1 b/Examples/Grouping/TimestampBucket.ps1 index da99152..6ce88f6 100644 --- a/Examples/Grouping/TimestampBucket.ps1 +++ b/Examples/Grouping/TimestampBucket.ps1 @@ -1,3 +1,4 @@ +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} $data = ConvertFrom-Csv @" Timestamp,Tenant 10/29/2018 3:00:00.123,1 @@ -15,8 +16,10 @@ Timestamp,Tenant 10/29/2018 3:02:00.999,1 "@ | Select-Object @{n = 'Timestamp'; e = {Get-date $_.timestamp}}, tenant, @{n = 'Bucket'; e = { - (Get-date $_.timestamp).Second % 30}} -$f = "$env:temp\pivottest.xlsx" -Remove-Item $f -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 $pivotDefParams = @{ PivotTableName = 'Timestamp Buckets' @@ -29,7 +32,7 @@ $pivotDefParams = @{ $excelParams = @{ PivotTableDefinition = New-PivotTableDefinition @pivotDefParams - Path = $f + Path = $xlSourcefile WorkSheetname = "Log Data" AutoSize = $true AutoFilter = $true diff --git a/Examples/HyperLinks/Races.ps1 b/Examples/HyperLinks/Races.ps1 index fefe945..05afe2e 100644 --- a/Examples/HyperLinks/Races.ps1 +++ b/Examples/HyperLinks/Races.ps1 @@ -3,6 +3,7 @@ #We will create links to each race in the first 10 rows of the spreadSheet #The next row will be column labels #After that will come a block for each race. +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} #Read the data, and decide how much space to leave for the hyperlinks $scriptPath = Split-Path -Path $MyInvocation.MyCommand.path -Parent diff --git a/Examples/JoinWorksheet/Join-Worksheet.sample.ps1 b/Examples/JoinWorksheet/Join-Worksheet.sample.ps1 index da3d468..1da18c4 100644 --- a/Examples/JoinWorksheet/Join-Worksheet.sample.ps1 +++ b/Examples/JoinWorksheet/Join-Worksheet.sample.ps1 @@ -1,4 +1,6 @@ -#Get rid of pre-exisiting sheet +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 diff --git a/Examples/JoinWorksheet/Join-worksheet-blocks.sample.ps1 b/Examples/JoinWorksheet/Join-worksheet-blocks.sample.ps1 index 2f7a950..91be30c 100644 --- a/Examples/JoinWorksheet/Join-worksheet-blocks.sample.ps1 +++ b/Examples/JoinWorksheet/Join-worksheet-blocks.sample.ps1 @@ -1,3 +1,4 @@ +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} $path = "$env:TEMP\Test.xlsx" Remove-item -Path $path -ErrorAction SilentlyContinue diff --git a/Examples/JoinWorksheet/JoinSalesData.ps1 b/Examples/JoinWorksheet/JoinSalesData.ps1 index f4463fb..a572e76 100644 --- a/Examples/JoinWorksheet/JoinSalesData.ps1 +++ b/Examples/JoinWorksheet/JoinSalesData.ps1 @@ -1,15 +1,16 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$xlfile = "$env:temp\AllSales.xlsx" - -Remove-Item $xlfile -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $params = @{ AutoSize = $true AutoFilter = $true AutoNameRange = $true ExcelChartDefinition = New-ExcelChartDefinition -XRange Item -YRange UnitSold -Title 'Units Sold' - Path = $xlfile + Path = $xlSourcefile } #Import 4 sets of sales data from 4 CSV files, using the parameters above. Import-Csv $PSScriptRoot\NorthSales.csv | Export-Excel -WorkSheetname North @params diff --git a/Examples/MergeWorkSheet/MergeCSV.ps1 b/Examples/MergeWorkSheet/MergeCSV.ps1 index af4f3c1..bef07e3 100644 --- a/Examples/MergeWorkSheet/MergeCSV.ps1 +++ b/Examples/MergeWorkSheet/MergeCSV.ps1 @@ -1,8 +1,9 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} -$xlFile = "$env:TEMP\mw.xlsx" - -Remove-Item $xlFile -ErrorAction Ignore +#Get rid of pre-exisiting sheet +$xlSourcefile = "$env:TEMP\ImportExcelExample.xlsx" +Write-Verbose -Verbose -Message "Save location: $xlSourcefile" +Remove-Item $xlSourcefile -ErrorAction Ignore $leftCsv = @" MyProp1,MyProp2,Length @@ -16,4 +17,4 @@ a,b,10 c,d,21 "@ | ConvertFrom-Csv -Merge-Worksheet -OutputFile $xlFile -ReferenceObject $leftCsv -DifferenceObject $rightCsv -Key Length -Show \ No newline at end of file +Merge-Worksheet -OutputFile $xlSourcefile -ReferenceObject $leftCsv -DifferenceObject $rightCsv -Key Length -Show \ No newline at end of file diff --git a/Examples/MergeWorkSheet/Merge_2_Servers_Services.ps1 b/Examples/MergeWorkSheet/Merge_2_Servers_Services.ps1 index b419fee..dc04116 100644 --- a/Examples/MergeWorkSheet/Merge_2_Servers_Services.ps1 +++ b/Examples/MergeWorkSheet/Merge_2_Servers_Services.ps1 @@ -1,3 +1,5 @@ +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} + Remove-Item -Path "$env:temp\server*.xlsx" , "$env:temp\Combined*.xlsx" -ErrorAction SilentlyContinue #Get a subset of services into $s and export them diff --git a/Examples/MergeWorkSheet/Merge_3_Servers_Services.ps1 b/Examples/MergeWorkSheet/Merge_3_Servers_Services.ps1 index d57b639..d2f3185 100644 --- a/Examples/MergeWorkSheet/Merge_3_Servers_Services.ps1 +++ b/Examples/MergeWorkSheet/Merge_3_Servers_Services.ps1 @@ -1,3 +1,5 @@ +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} + Remove-Item -Path "$env:temp\server*.xlsx" , "$env:temp\Combined*.xlsx" -ErrorAction SilentlyContinue #Get a subset of services into $s and export them diff --git a/Examples/MortgageCalculator/MortgageCalculator.ps1 b/Examples/MortgageCalculator/MortgageCalculator.ps1 index 783d54b..2b0f7d6 100644 --- a/Examples/MortgageCalculator/MortgageCalculator.ps1 +++ b/Examples/MortgageCalculator/MortgageCalculator.ps1 @@ -7,7 +7,7 @@ param( $InterestRate = .065, $Term = 30 ) - +try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return} function New-CellData { [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification='Does not change system state')] param(