Standardising examples

This commit is contained in:
MikeyBronowski
2020-07-01 22:04:37 +02:00
parent 0a77a83e35
commit 8a20963577
50 changed files with 249 additions and 154 deletions

View File

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

View File

@@ -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
$data | Export-Excel $xlSourcefile -show -ConditionalText $ContainsBlanks

View File

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

View File

@@ -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 <parameters>) <other parameters>
#$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)

View File

@@ -1,3 +1,5 @@
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
function Get-DateOffset {
param($days=0)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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)
$data | Export-Excel $xlSourcefile -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType DuplicateValues)

View File

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

View File

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

View File

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

View File

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

View File

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