aggressive linting

This commit is contained in:
jhoneill
2019-11-20 19:14:19 +00:00
parent 873f1a365b
commit 5aa841c225
47 changed files with 218 additions and 189 deletions

View File

@@ -1,15 +1,15 @@
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
$xlSourcefile = "$env:TEMP\Source.xlsx"
write-host "Save location: $xlSourcefile"
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
$TabData1 = 1..5 | Export-Excel $xlSourcefile -WorksheetName 'Tab1' -AutoSize -AutoFilter
1..5 | Export-Excel $xlSourcefile -WorksheetName 'Tab1' -AutoSize -AutoFilter
#Add another tab. Replace the $TabData2 with your data
$TabData2 = 1..10 | Export-Excel $xlSourcefile -WorksheetName 'Tab 2' -AutoSize -AutoFilter
1..10 | Export-Excel $xlSourcefile -WorksheetName 'Tab 2' -AutoSize -AutoFilter
#Add another tab. Replace the $TabData3 with your data
$TabData3 = 1..15 | Export-Excel $xlSourcefile -WorksheetName 'Tab 3' -AutoSize -AutoFilter -Show
1..15 | Export-Excel $xlSourcefile -WorksheetName 'Tab 3' -AutoSize -AutoFilter -Show

View File

@@ -25,4 +25,4 @@ function plot {
function pi {[math]::pi}
plot {[math]::Tan($args[0])} (pi) (3*(pi)/2-.01)
plot -f {[math]::Tan($args[0])} -minx (pi) -maxx (3*(pi)/2-.01)

View File

@@ -1,9 +1,9 @@
echo Last7Days LastMonth LastWeek NextMonth NextWeek ThisMonth ThisWeek Today Tomorrow Yesterday |
"Last7Days", "LastMonth", "LastWeek", "NextMonth", "NextWeek", "ThisMonth", "ThisWeek", "Today", "Tomorrow", "Yesterday" |
Foreach-Object {
$text = @"
`$f = ".\testExport.xlsx"
rm `$f -ErrorAction Ignore
remove-item `$f -ErrorAction Ignore
.\GenDates.ps1 |
Export-Excel `$f -Show -AutoSize -ConditionalText `$(

View File

@@ -4,7 +4,7 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
$ContainsBlanks = New-ConditionalText -ConditionalType ContainsBlanks
$data = $(
New-PSItem a b c (echo p1 p2 p3)
New-PSItem a b c @('p1', 'p2', 'p3')
New-PSItem
New-PSItem d e f
New-PSItem

View File

@@ -10,23 +10,23 @@ $excel = Get-Process |
$sheet = $excel.Workbook.Worksheets["Processes"]
#Apply fixed formatting to columns. Set-Format is an Alias for Set-Excel Range, -NFormat is an alias for numberformat
#Apply fixed formatting to columns. -NFormat is an alias for numberformat
$sheet.Column(1) | Set-ExcelRange -Bold -AutoFit
$sheet.Column(2) | Set-Format -Width 29 -WrapText
$sheet.Column(3) | Set-Format -HorizontalAlignment Right -NFormat "#,###"
$sheet.Column(2) | Set-ExcelRange -Width 29 -WrapText
$sheet.Column(3) | Set-ExcelRange -HorizontalAlignment Right -NFormat "#,###"
Set-ExcelRange -Range -Address $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NFormat "#,###"
#Set-Format is an alias for Set-ExcelRange
Set-Format -Range $sheet.Column(4) -HorizontalAlignment Right -NFormat "#,##0.0" -Bold
#In Set-ExcelRange / Set-Format "-Address" is an alias for "-Range"
Set-Format -Address $sheet.Row(1) -Bold -HorizontalAlignment Center
Set-ExcelRange -Range $sheet.Column(4) -HorizontalAlignment Right -NFormat "#,##0.0" -Bold
#In Set-ExcelRange "-Address" is an alias for "-Range"
Set-ExcelRange -Address $sheet.Row(1) -Bold -HorizontalAlignment Center
#Create a Red Data-bar for the values in Column D
Add-ConditionalFormatting -WorkSheet $sheet -Address "D2:D1048576" -DataBarColor Red
# Conditional formatting applies to "Addreses" aliases allow either "Range" or "Address" to be used in Set-ExcelRange or Add-Conditional formatting.
Add-ConditionalFormatting -WorkSheet $sheet -Range "G2:G1048576" -RuleType GreaterThan -ConditionValue "104857600" -ForeGroundColor Red
foreach ($c in 5..9) {Set-Format -Address $sheet.Column($c) -AutoFit }
foreach ($c in 5..9) {Set-ExcelRange -Address $sheet.Column($c) -AutoFit }
#Create a pivot and save the file.
Export-Excel -ExcelPackage $excel -WorkSheetname "Processes" -IncludePivotChart -ChartType ColumnClustered -NoLegend -PivotRows company -PivotData @{'Name'='Count'} -Show

View File

@@ -6,7 +6,7 @@ Remove-Item $f -ErrorAction Ignore
$data = $(
New-PSItem North 111 (echo Region Amount )
New-PSItem North 111 @( 'Region', 'Amount' )
New-PSItem East 111
New-PSItem West 122
New-PSItem South 200

View File

@@ -1,6 +1,6 @@
function Get-DateOffset {
param($days=0)
(Get-Date).AddDays($days).ToShortDateString()
}
@@ -8,7 +8,7 @@ function Get-Number {
Get-Random -Minimum 10 -Maximum 100
}
New-PSItem (Get-DateOffset -7) (Get-Number) 'LastWeek,Last7Days,ThisMonth' (echo Date Amount Label)
New-PSItem (Get-DateOffset -7) (Get-Number) 'LastWeek,Last7Days,ThisMonth' @('Date', 'Amount', 'Label')
New-PSItem (Get-DateOffset) (Get-Number) 'Today,ThisMonth,ThisWeek'
New-PSItem (Get-DateOffset -30) (Get-Number) LastMonth
New-PSItem (Get-DateOffset -1) (Get-Number) 'Yesterday,ThisMonth,ThisWeek'

View File

@@ -6,7 +6,7 @@ Remove-Item $f -ErrorAction Ignore
$data = $(
New-PSItem North 111 (echo Region Amount )
New-PSItem North 111 @('Region', 'Amount' )
New-PSItem East 11
New-PSItem West 12
New-PSItem South 1000

View File

@@ -8,7 +8,7 @@ function Get-DateOffset ($days=0) {
}
$(
New-PSItem (Get-DateOffset -1) (Get-DateOffset 1) (echo Start End)
New-PSItem (Get-DateOffset -1) (Get-DateOffset 1) @("Start", "End")
New-PSItem (Get-DateOffset) (Get-DateOffset 7)
New-PSItem (Get-DateOffset -10) (Get-DateOffset -1)
) |

View File

@@ -16,7 +16,7 @@ Jun,621
$sheet = $excel.Workbook.Worksheets["Sheet1"]
Add-ConditionalFormatting -WorkSheet $sheet -Range "B1:B7" -DataBarColor LawnGreen
Set-Format -Address $sheet.Cells["A8"] -Value "Total"
Set-Format -Address $sheet.Cells["B8"] -Formula "=Sum(Sales)"
Set-ExcelRange -Address $sheet.Cells["A8"] -Value "Total"
Set-ExcelRange -Address $sheet.Cells["B8"] -Formula "=Sum(Sales)"
Close-ExcelPackage $excel -Show

View File

@@ -1,7 +1,7 @@
try {ipmo ..\..\ImportExcel.psd1 -Force} catch {}
try {Import-Module ..\..\ImportExcel.psd1 -Force} catch {throw ; return}
$data = $(
New-PSItem 100 (echo test testx)
New-PSItem 100 @('test', 'testx')
New-PSItem 200
New-PSItem 300
New-PSItem 400
@@ -11,8 +11,8 @@ $data = $(
$file1 = "$env:Temp\tryComparison1.xlsx"
$file2 = "$env:Temp\tryComparison2.xlsx"
rm $file1 -ErrorAction Ignore
rm $file2 -ErrorAction Ignore
Remove-Item -Path $file1 -ErrorAction Ignore
Remove-Item -Path $file2 -ErrorAction Ignore
$data | Export-Excel $file1 -Show -ConditionalText $(
New-ConditionalText -ConditionalType GreaterThan 300

View File

@@ -22,51 +22,51 @@ $sheet1 = $excel.Workbook.Worksheets["sheet1"]
$sheet1.View.ShowGridLines = $false
$sheet1.View.ShowHeaders = $false
Set-Format -Address $sheet1.Cells["C:C"] -NumberFormat "$#,##0" -WrapText -HorizontalAlignment Center
Set-Format -Address $sheet1.Cells["D:D"] -NumberFormat "#.#0%" -WrapText -HorizontalAlignment Center
Set-ExcelRange -Address $sheet1.Cells["C:C"] -NumberFormat "$#,##0" -WrapText -HorizontalAlignment Center
Set-ExcelRange -Address $sheet1.Cells["D:D"] -NumberFormat "#.#0%" -WrapText -HorizontalAlignment Center
Set-Format -Address $sheet1.Cells["E:E"] -NumberFormat "$#,##0" -WrapText -HorizontalAlignment Center
Set-Format -Address $sheet1.Cells["F:F"] -NumberFormat "#.#0%" -WrapText -HorizontalAlignment Center
Set-ExcelRange -Address $sheet1.Cells["E:E"] -NumberFormat "$#,##0" -WrapText -HorizontalAlignment Center
Set-ExcelRange -Address $sheet1.Cells["F:F"] -NumberFormat "#.#0%" -WrapText -HorizontalAlignment Center
Set-Format -Address $sheet1.Cells["G:H"] -WrapText -HorizontalAlignment Center
Set-ExcelRange -Address $sheet1.Cells["G:H"] -WrapText -HorizontalAlignment Center
## Insert Rows/Columns
$sheet1.InsertRow(1, 1)
foreach ($col in Write-Output 2 4 6 8 10 12 14) {
foreach ($col in @(2, 4, 6, 8, 10, 12, 14)) {
$sheet1.InsertColumn($col, 1)
$sheet1.Column($col).width = .75
}
Set-Format -Address $sheet1.Cells["E:E"] -Width 12
Set-Format -Address $sheet1.Cells["I:I"] -Width 12
Set-ExcelRange -Address $sheet1.Cells["E:E"] -Width 12
Set-ExcelRange -Address $sheet1.Cells["I:I"] -Width 12
$BorderBottom = "Thick"
$BorderColor = "Black"
Set-Format -Address $sheet1.Cells["A2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
Set-ExcelRange -Address $sheet1.Cells["A2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
Set-Format -Address $sheet1.Cells["C2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
Set-Format -Address $sheet1.Cells["E2:G2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
Set-Format -Address $sheet1.Cells["I2:K2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
Set-Format -Address $sheet1.Cells["M2:O2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
Set-ExcelRange -Address $sheet1.Cells["C2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
Set-ExcelRange -Address $sheet1.Cells["E2:G2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
Set-ExcelRange -Address $sheet1.Cells["I2:K2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
Set-ExcelRange -Address $sheet1.Cells["M2:O2"] -BorderBottom $BorderBottom -BorderColor $BorderColor
Set-Format -Address $sheet1.Cells["A2:C8"] -FontColor Gray
Set-ExcelRange -Address $sheet1.Cells["A2:C8"] -FontColor Gray
$HorizontalAlignment = "Center"
Set-Format -Address $sheet1.Cells["F1"] -HorizontalAlignment $HorizontalAlignment -Bold -Value Revenue
Set-Format -Address $sheet1.Cells["J1"] -HorizontalAlignment $HorizontalAlignment -Bold -Value Margin
Set-Format -Address $sheet1.Cells["N1"] -HorizontalAlignment $HorizontalAlignment -Bold -Value Passenger
Set-ExcelRange -Address $sheet1.Cells["F1"] -HorizontalAlignment $HorizontalAlignment -Bold -Value Revenue
Set-ExcelRange -Address $sheet1.Cells["J1"] -HorizontalAlignment $HorizontalAlignment -Bold -Value Margin
Set-ExcelRange -Address $sheet1.Cells["N1"] -HorizontalAlignment $HorizontalAlignment -Bold -Value Passenger
Set-Format -Address $sheet1.Cells["E2"] -Value '($)'
Set-Format -Address $sheet1.Cells["G2"] -Value '%'
Set-Format -Address $sheet1.Cells["I2"] -Value '($)'
Set-Format -Address $sheet1.Cells["K2"] -Value '%'
Set-ExcelRange -Address $sheet1.Cells["E2"] -Value '($)'
Set-ExcelRange -Address $sheet1.Cells["G2"] -Value '%'
Set-ExcelRange -Address $sheet1.Cells["I2"] -Value '($)'
Set-ExcelRange -Address $sheet1.Cells["K2"] -Value '%'
Set-Format -Address $sheet1.Cells["C10"] -HorizontalAlignment Right -Bold -Value "Grand Total Calculation"
Set-Format -Address $sheet1.Cells["E10"] -Formula "=Sum(E3:E8)" -Bold
Set-Format -Address $sheet1.Cells["I10"] -Formula "=Sum(I3:I8)" -Bold
Set-Format -Address $sheet1.Cells["M10"] -Formula "=Sum(M3:M8)" -Bold
Set-Format -Address $sheet1.Cells["O10"] -Formula "=Sum(O3:O8)" -Bold
Set-ExcelRange -Address $sheet1.Cells["C10"] -HorizontalAlignment Right -Bold -Value "Grand Total Calculation"
Set-ExcelRange -Address $sheet1.Cells["E10"] -Formula "=Sum(E3:E8)" -Bold
Set-ExcelRange -Address $sheet1.Cells["I10"] -Formula "=Sum(I3:I8)" -Bold
Set-ExcelRange -Address $sheet1.Cells["M10"] -Formula "=Sum(M3:M8)" -Bold
Set-ExcelRange -Address $sheet1.Cells["O10"] -Formula "=Sum(O3:O8)" -Bold
Close-ExcelPackage $excel -Show

View File

@@ -11,7 +11,7 @@ $RandomStyle = {
)
2..$totalRows | ForEach-Object{
Set-CellStyle $workSheet $_ $LastColumn Solid (Write-Output LightGreen Gray Red|Get-Random)
Set-CellStyle $workSheet $_ $LastColumn Solid (Get-Random @("LightGreen", "Gray", "Red"))
}
}

View File

@@ -1,26 +1,26 @@
if(!(gcm ig -ErrorAction SilentlyContinue)) {
if(!(Get-Command ig -ErrorAction SilentlyContinue)) {
"Use ``Install-Module NameIT`` to get the needed module from the gallery to support running this script"
return
}
}
$sign=@{sign=echo + -}
$location=@{location=echo Atlanta Newark Washington Chicago Philadelphia Houston Phoneix}
$sign=@{sign=@( "+", "-" )}
$location=@{location=@("Atlanta", "Newark", "Washington", "Chicago", "Philadelphia", "Houston", "Phoneix")}
$(1..6 | Foreach-Object {
$from=$to=""
while($from -eq $to) {
$from=ig "[location]" -CustomData $location
$to=ig "[location]" -CustomData $location
}
}
[double]$a=ig "########"
[double]$b=ig ".####"
[double]$c=ig "#######"
[double]$d=ig "[sign].##" -CustomData $sign
[double]$e=ig "###"
[double]$e=ig "###"
[double]$f=ig "[sign]##" -CustomData $sign
#"{0},{1},{2},{3},{4},{5},{6},{7}" -f $from, $to, $a, $b, $c, $d, $e, $f

View File

@@ -2,7 +2,7 @@
$path = "$env:TEMP\Test.xlsx"
Remove-item -Path $path -ErrorAction SilentlyContinue
#Export disk volume, and Network adapter to their own sheets.
Get-WmiObject -Class win32_logicaldisk |
Get-CimInstance -ClassName Win32_LogicalDisk |
Select-Object -Property DeviceId,VolumeName, Size,Freespace |
Export-Excel -Path $path -WorkSheetname Volumes -NumberFormat "0,000"
Get-NetAdapter |

View File

@@ -1,4 +1,4 @@
$PropertyNames = echo Cost Date Name
$PropertyNames = @("Cost", "Date", "Name")
New-PSItem 1.1 1/1/2015 John $PropertyNames
New-PSItem 2.1 1/2/2015 Tom

View File

@@ -9,6 +9,7 @@ param(
)
function New-CellData {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification='Does not change system state')]
param(
$Range,
$Value,
@@ -28,7 +29,7 @@ function New-CellData {
$setFormatParams.Value = $Value
}
Set-Format @setFormatParams
Set-ExcelRange @setFormatParams
}
$f = "$PSScriptRoot\mortgage.xlsx"
@@ -37,19 +38,19 @@ Remove-Item $f -ErrorAction SilentlyContinue
$pkg = "" | Export-Excel $f -Title 'Fixed Rate Loan Payments' -PassThru -AutoSize
$ws = $pkg.Workbook.Worksheets["Sheet1"]
New-CellData A3 'Amount'
New-CellData B3 $Amount '$#,##0'
New-CellData -Range A3 -Value 'Amount'
New-CellData -Range B3 -Value $Amount -Format '$#,##0'
New-CellData A4 "Interest Rate"
New-CellData B4 $InterestRate 'Percentage'
New-CellData -Range A4 -Value "Interest Rate"
New-CellData -Range B4 -Value $InterestRate -Format 'Percentage'
New-CellData A5 "Term (Years)"
New-CellData B5 $Term
New-CellData -Range A5 -Value "Term (Years)"
New-CellData -Range B5 -Value $Term
New-CellData D3 "Monthly Payment"
New-CellData F3 "=-PMT(F4, B5*12, B3)" '$#,##0.#0'
New-CellData -Range D3 -Value "Monthly Payment"
New-CellData -Range F3 -Value "=-PMT(F4, B5*12, B3)" -Format '$#,##0.#0'
New-CellData D4 "Monthly Rate"
New-CellData F4 "=((1+B4)^(1/12))-1" 'Percentage'
New-CellData -Range D4 -Value "Monthly Rate"
New-CellData -Range F4 -Value "=((1+B4)^(1/12))-1" -Format 'Percentage'
Close-ExcelPackage $pkg -Show

View File

@@ -1,16 +1,17 @@
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
$header = echo `
'Date/Time - Peak Brightness (UT)' `
'Latitude (Deg)' `
'Longitude (Deg)' `
'Altitude (km)' `
'Velocity (km/s)' `
'Velocity Components (km/s) vx' `
'Velocity Components (km/s) vy' `
'Velocity Components (km/s) vz' `
'Total Radiated Energy (J)' `
$header = @(
'Date/Time - Peak Brightness (UT)' ,
'Latitude (Deg)' ,
'Longitude (Deg)' ,
'Altitude (km)' ,
'Velocity (km/s)' ,
'Velocity Components (km/s) vx' ,
'Velocity Components (km/s) vy' ,
'Velocity Components (km/s) vz' ,
'Total Radiated Energy (J)' ,
'Calculated Total Impact Energy (kt)'
)
$splat=@{
url='http://neo.jpl.nasa.gov/fireballs/'

View File

@@ -1,5 +1,6 @@
function New-PSItem {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification='Does not change system state')]
param()
$totalArgs = $args.Count
if($args[-1] -is [array]) {

View File

@@ -3,10 +3,10 @@
## This is an overhaul of Jeffrey Snover's original Start-Demo script by Joel "Jaykul" Bennett
##
## I've switched it to using ReadKey instead of ReadLine (you don't have to hit Enter each time)
## As a result, I've changed the names and keys for a lot of the operations, so that they make
## As a result, I've changed the names and keys for a lot of the operations, so that they make
## sense with only a single letter to tell them apart (sorry if you had them memorized).
##
## I've also been adding features as I come across needs for them, and you'll contribute your
## I've also been adding features as I come across needs for them, and you'll contribute your
## improvements back to the PowerShell Script repository as well.
##################################################################################################
## Revision History (version 3.3)
@@ -32,12 +32,14 @@
## so you have a chance to "go back" after the last line of you demo
##################################################################################################
##
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification='Correct and desirable usage')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingInvokeExpression', '', Justification='Correct and desirable usage')]
param(
$file=".\demo.txt",
[int]$command=0,
[System.ConsoleColor]$promptColor="Yellow",
[System.ConsoleColor]$commandColor="White",
[System.ConsoleColor]$commentColor="Green",
$file=".\demo.txt",
[int]$command=0,
[System.ConsoleColor]$promptColor="Yellow",
[System.ConsoleColor]$commandColor="White",
[System.ConsoleColor]$commentColor="Green",
[switch]$FullAuto,
[int]$AutoSpeed = 3,
[switch]$NoPauseAfterExecute
@@ -46,7 +48,7 @@ param(
$RawUI = $Host.UI.RawUI
$hostWidth = $RawUI.BufferSize.Width
# A function for reading in a character
# A function for reading in a character
function Read-Char() {
$_OldColor = $RawUI.ForeGroundColor
$RawUI.ForeGroundColor = "Red"
@@ -93,20 +95,20 @@ Write-Host -nonew -back black -fore $promptColor "for help.$(' ' * ($hostWidth -
Write-Host -nonew -back black -fore $promptColor $(" " * $hostWidth)
# We use a FOR and an INDEX ($_i) instead of a FOREACH because
# it is possible to start at a different location and/or jump
# it is possible to start at a different location and/or jump
# around in the order.
for ($_i = $Command; $_i -lt $_lines.count; $_i++)
{
{
# Put the current command in the Window Title along with the demo duration
$Dur = [DateTime]::Now - $_StartTime
$RawUI.WindowTitle = "$(if($dur.Hours -gt 0){'{0}h '})$(if($dur.Minutes -gt 0){'{1}m '}){2}s {3}" -f
$RawUI.WindowTitle = "$(if($dur.Hours -gt 0){'{0}h '})$(if($dur.Minutes -gt 0){'{1}m '}){2}s {3}" -f
$dur.Hours, $dur.Minutes, $dur.Seconds, $($_Lines[$_i])
# Echo out the commmand to the console with a prompt as though it were real
Write-Host -nonew -fore $promptColor "[$_i]$([char]0x2265) "
if ($_lines[$_i].Trim(" ").StartsWith("#") -or $_lines[$_i].Trim(" ").Length -le 0) {
if ($_lines[$_i].Trim(" ").StartsWith("#") -or $_lines[$_i].Trim(" ").Length -le 0) {
Write-Host -fore $commentColor "$($_Lines[$_i]) "
continue
continue
} else {
Write-Host -nonew -fore $commandColor "$($_Lines[$_i]) "
}
@@ -119,7 +121,7 @@ for ($_i = $Command; $_i -lt $_lines.count; $_i++)
Running demo: $file
(n) Next (p) Previous
(q) Quit (s) Suspend
(q) Quit (s) Suspend
(t) Timecheck (v) View $(split-path $file -leaf)
(g) Go to line by number
(f) Find lines by string
@@ -148,15 +150,15 @@ Running demo: $file
break;
}
"v" { # View Source
$lines[0..($_i-1)] | Write-Host -Fore Yellow
$lines[0..($_i-1)] | Write-Host -Fore Yellow
$lines[$_i] | Write-Host -Fore Green
$lines[($_i+1)..$lines.Count] | Write-Host -Fore Yellow
$lines[($_i+1)..$lines.Count] | Write-Host -Fore Yellow
$_i-- # back a line, we're gonna step forward when we loop
}
"t" { # Time Check
$dur = [DateTime]::Now - $_StartTime
Write-Host -Fore $promptColor $(
"{3} -- $(if($dur.Hours -gt 0){'{0}h '})$(if($dur.Minutes -gt 0){'{1}m '}){2}s" -f
"{3} -- $(if($dur.Hours -gt 0){'{0}h '})$(if($dur.Minutes -gt 0){'{1}m '}){2}s" -f
$dur.Hours, $dur.Minutes, $dur.Seconds, ([DateTime]::Now.ToShortTimeString()))
$_i-- # back a line, we're gonna step forward when we loop
}
@@ -170,7 +172,7 @@ Running demo: $file
if($i -le $_lines.Count) {
if($i -gt 0) {
# extra line back because we're gonna step forward when we loop
$_i = Rewind $_lines $_i (($_i-$i)+1)
$_i = Rewind -lines $_lines -index $_i -steps (($_i-$i)+1)
} else {
$_i = -1 # Start negative, because we step forward when we loop
}
@@ -178,18 +180,18 @@ Running demo: $file
}
"f" { # Find by pattern
$match = $_lines | Select-String (Read-Host "search string")
if($match -eq $null) {
if($null -eq $match) {
Write-Host -Fore Red "Can't find a matching line"
} else {
$match | % { Write-Host -Fore $promptColor $("[{0,2}] {1}" -f ($_.LineNumber - 1), $_.Line) }
$match | ForEach-Object { Write-Host -Fore $promptColor $("[{0,2}] {1}" -f ($_.LineNumber - 1), $_.Line) }
if($match.Count -lt 1) {
$_i = $match.lineNumber - 2 # back a line, we're gonna step forward when we loop
} else {
} else {
$_i-- # back a line, we're gonna step forward when we loop
}
}
}
"c" {
"c" {
Clear-Host
$_i-- # back a line, we're gonna step forward when we loop
}
@@ -197,7 +199,7 @@ Running demo: $file
Write-Host
trap [System.Exception] {Write-Error $_; continue;}
Invoke-Expression ($_lines[$_i]) | out-default
if(-not $NoPauseAfterExecute -and -not $FullAuto) {
if(-not $NoPauseAfterExecute -and -not $FullAuto) {
$null = $RawUI.ReadKey("NoEcho,IncludeKeyUp") # Pause after output for no apparent reason... ;)
}
}
@@ -210,7 +212,7 @@ Running demo: $file
}
$dur = [DateTime]::Now - $_StartTime
Write-Host -Fore $promptColor $(
"<Demo Complete -- $(if($dur.Hours -gt 0){'{0}h '})$(if($dur.Minutes -gt 0){'{1}m '}){2}s>" -f
"<Demo Complete -- $(if($dur.Hours -gt 0){'{0}h '})$(if($dur.Minutes -gt 0){'{1}m '}){2}s>" -f
$dur.Hours, $dur.Minutes, $dur.Seconds, [DateTime]::Now.ToLongTimeString())
Write-Host -Fore $promptColor $([DateTime]::now)
Write-Host

View File

@@ -20,11 +20,11 @@ $pivotTableParams = @{
PivotTableName = "ByRegion"
Address = $excel.Sheet1.cells["F1"]
SourceWorkSheet = $excel.Sheet1
PivotRows = echo Region Fruit Date
PivotRows = @("Region", "Fruit", "Date")
PivotData = @{'sold' = 'sum'}
PivotTableStyle = 'Light21'
GroupDateRow = "Date"
GroupDatePart = echo Years Quarters
GroupDatePart = @("Years", "Quarters")
}
$pt = Add-PivotTable @pivotTableParams -PassThru
@@ -33,21 +33,21 @@ $pt.RowHeaderCaption = "By " + ($pivotTableParams.PivotRows -join ",")
$pivotTableParams.PivotTableName = "ByFruit"
$pivotTableParams.Address = $excel.Sheet1.cells["J1"]
$pivotTableParams.PivotRows = echo Fruit Region Date
$pivotTableParams.PivotRows = @("Fruit", "Region", "Date")
$pt = Add-PivotTable @pivotTableParams -PassThru
$pt.RowHeaderCaption = "By Fruit,Region"
$pivotTableParams.PivotTableName = "ByDate"
$pivotTableParams.Address = $excel.Sheet1.cells["N1"]
$pivotTableParams.PivotRows = echo Date Region Fruit
$pivotTableParams.PivotRows = @("Date", "Region", "Fruit")
$pt = Add-PivotTable @pivotTableParams -PassThru
$pt.RowHeaderCaption = "By Date,Region,Fruit"
$pivotTableParams.PivotTableName = "ByYears"
$pivotTableParams.Address = $excel.Sheet1.cells["S1"]
$pivotTableParams.GroupDatePart = echo Years
$pivotTableParams.GroupDatePart = "Years"
$pt = Add-PivotTable @pivotTableParams -PassThru
$pt.RowHeaderCaption = "By Years,Region"

View File

@@ -10,10 +10,10 @@ $hash = @{ }
$e = Open-ExcelPackage $path
foreach ($sheet in $e.workbook.worksheets) {
$hash[$sheet.name] = Import-Excel -ExcelPackage $e -WorksheetName $sheet.name
}
foreach ($sheet in $e.workbook.worksheets) {
$hash[$sheet.name] = Import-Excel -ExcelPackage $e -WorksheetName $sheet.name
}
Close-ExcelPackage $e -NoSave
Close-ExcelPackage $e -NoSave
$hash

View File

@@ -1,4 +1,4 @@
$xlfile = "$env:TEMP\MultipleSheets.xlsx"
.\GenerateXlsx.ps1 $xlfile
.\Get-ExcelSheets.ps1 $xlfile
.\GenerateXlsx.ps1 $xlfile
.\Get-ExcelSheets.ps1 $xlfile

View File

@@ -44,17 +44,17 @@ Remove-Item -Path "~\Documents\temp.xlsx" -ErrorAction SilentlyContinue
$e = Send-SQLDataToExcel -Path "~\Documents\temp.xlsx" -WorkSheetname "Sheet1" -Connection "DSN=LR" -SQL $sql -AutoSize -Passthru
#Add columns, then format them and hide the ones which aren't of interest.
Set-Column -Worksheet $e.workbook.Worksheets["sheet1"] -Column 21 -Value $Avalue -Heading "Apperture"
Set-Column -Worksheet $e.workbook.Worksheets["sheet1"] -Column 22 -Value $Svalue -Heading "Shutter"
Set-Column -Worksheet $e.workbook.Worksheets["sheet1"] -Column 23 -Value $Evvalue -Heading "Ev"
Set-Format -Address $e.workbook.Worksheets["sheet1" ].Column(21) -HorizontalAlignment Left -AutoFit
Set-Format -Address $e.workbook.Worksheets["sheet1" ].Column(22) -HorizontalAlignment Right -AutoFit
Set-ExcelColumn -Worksheet $e.workbook.Worksheets["sheet1"] -Column 21 -Value $Avalue -Heading "Apperture"
Set-ExcelColumn -Worksheet $e.workbook.Worksheets["sheet1"] -Column 22 -Value $Svalue -Heading "Shutter"
Set-ExcelColumn -Worksheet $e.workbook.Worksheets["sheet1"] -Column 23 -Value $Evvalue -Heading "Ev"
Set-ExcelRange -Address $e.workbook.Worksheets["sheet1" ].Column(21) -HorizontalAlignment Left -AutoFit
Set-ExcelRange -Address $e.workbook.Worksheets["sheet1" ].Column(22) -HorizontalAlignment Right -AutoFit
@(5,6,7,13,15,16,17,18) | ForEach-Object {
Set-Format -Address $e.workbook.Worksheets["sheet1" ].Column($_) -Hidden
Set-ExcelRange -Address $e.workbook.Worksheets["sheet1" ].Column($_) -Hidden
}
#Center the column labels.
Set-Format -Address $e.workbook.Worksheets["sheet1" ].Row(1) -HorizontalAlignment Center
Set-ExcelRange -Address $e.workbook.Worksheets["sheet1" ].Row(1) -HorizontalAlignment Center
#Format the data as a nice Table, Create the pivot table & chart defined above, show the file in Excel in excel after saving.
Export-Excel -ExcelPackage $e -WorkSheetname "sheet1" -TableName "Table" -PivotTableDefinition $pt -Show
@@ -78,10 +78,10 @@ $SQL = @"
#Run the query and put the results in workshet "Winners", autosize the columns and hold on to the ExcelPackage object
$Excel = Send-SQLDataToExcel -SQL $sql -Session $session -path .\demo3.xlsx -WorkSheetname "Winners" -AutoSize -Passthru
#Create and format columns for the ratio of Wins to poles and fast laps.
Set-Column -ExcelPackage $Excel -WorkSheetname "Winners" -column 6 -Heading "WinsToPoles" -Value {"=D$row/C$row"}
Set-Column -ExcelPackage $Excel -WorkSheetname "Winners" -column 7 -Heading "WinsToFast" -Value {"=E$row/C$row"}
Set-ExcelColumn -ExcelPackage $Excel -WorkSheetname "Winners" -column 6 -Heading "WinsToPoles" -Value {"=D$row/C$row"}
Set-ExcelColumn -ExcelPackage $Excel -WorkSheetname "Winners" -column 7 -Heading "WinsToFast" -Value {"=E$row/C$row"}
6..7 | ForEach-Object {
Set-Format -Address $Excel.Workbook.Worksheets["Winners"].column($_) -NumberFormat "0.0%" -AutoFit }
Set-ExcelRange -Address $Excel.Workbook.Worksheets["Winners"].column($_) -NumberFormat "0.0%" -AutoFit }
#Define a chart to show the relationship of lest on an XY Grid, create the ranges required in the, add the chart and show the file in Excel in excel after saving.
$chart = New-ExcelChart -NoLegend -ChartType XYScatter -XRange WinsToFast -YRange WinsToPoles -ShowCategory -Column 7 -Width 2000 -Height 700
Export-Excel -ExcelPackage $Excel -WorkSheetname "Winners" -AutoNameRange -ExcelChartDefinition $chart -Show

View File

@@ -19,6 +19,6 @@ Set-Row -Worksheet $ws -Heading "Average" -Value {"=Average($columnName`2
Set-Column -Worksheet $ws -Heading "WinsToPoles" -Value {"=D$row/C$row"} -Column 6 -AutoSize -AutoNameRange
Set-Column -Worksheet $ws -Heading "WinsToFast" -Value {"=E$row/C$row"} -Column 7 -AutoSize -AutoNameRange
Set-Format -WorkSheet $ws -Range "F2:G50" -NumberFormat "0.0%"
Set-ExcelRange -WorkSheet $ws -Range "F2:G50" -NumberFormat "0.0%"
$chart = New-ExcelChart -NoLegend -ChartType XYScatter -XRange WinsToFast -YRange WinsToPoles -Column 7 -Width 2000 -Height 700 -Title "Poles vs fastlaps"
Export-Excel -ExcelPackage $Excel -WorkSheetname "Winners" -ExcelChartDefinition $chart -Show

View File

@@ -15,7 +15,7 @@ $excel = $data | Export-Excel $xlfile -Passthru -AutoSize -TableName SalesByQuar
$ws = $excel.Sheet1
Set-Format -WorkSheet $ws -Range "B2:E5" -NumberFormat "$#,##0" -AutoSize
Set-ExcelRange -WorkSheet $ws -Range "B2:E5" -NumberFormat "$#,##0" -AutoSize
$sparkLineType = "line"
$null = $ws.SparklineGroups.Add( $sparkLineType, $ws.Cells["F2"], $ws.Cells["B2:E2"] )
$null = $ws.SparklineGroups.Add( $sparkLineType, $ws.Cells["F3"], $ws.Cells["B3:E3"] )

View File

@@ -41,8 +41,8 @@ Remove-Item $xlfile -ErrorAction SilentlyContinue
$excel = $data | Export-Excel $xlfile -WorksheetName SEKRates -AutoSize -PassThru
# Add a column sparkline for all currencies
Set-Format -WorkSheet $excel.SEKRates -Range "A2:A12" -NumberFormat "yyyy-mm-dd" -AutoSize
Set-Format -WorkSheet $excel.SEKRates -Range A15 -Value Column -AutoSize
Set-ExcelRange -WorkSheet $excel.SEKRates -Range "A2:A12" -NumberFormat "yyyy-mm-dd" -AutoSize
Set-ExcelRange -WorkSheet $excel.SEKRates -Range A15 -Value Column -AutoSize
$sparklineCol = $excel.SEKRates.SparklineGroups.Add(
"Column",
@@ -54,7 +54,7 @@ $sparklineCol.High = $true
$sparklineCol.ColorHigh.SetColor("Red")
# Add a line sparkline for all currencies
Set-Format -WorkSheet $excel.SEKRates -Range A16 -Value Line -AutoSize
Set-ExcelRange -WorkSheet $excel.SEKRates -Range A16 -Value Line -AutoSize
$sparklineLine = $excel.SEKRates.SparklineGroups.Add(
"Line",
$excel.SEKRates.Cells["B16:Q16"],
@@ -64,7 +64,7 @@ $sparklineLine = $excel.SEKRates.SparklineGroups.Add(
$sparklineLine.DateAxisRange = $excel.SEKRates.Cells["A2:A12"]
# Add some more random values and add a stacked sparkline.
Set-Format -WorkSheet $excel.SEKRates -Range A17 -Value Stacked -AutoSize
Set-ExcelRange -WorkSheet $excel.SEKRates -Range A17 -Value Stacked -AutoSize
$numbers = 2, -1, 3, -4, 8, 5, -12, 18, 99, 1, -4, 12, -8, 9, 0, -8
@@ -86,7 +86,7 @@ $sparklineStacked.ColorLow.SetColor("Green")
$sparklineStacked.Negative = $true
$sparklineStacked.ColorNegative.SetColor("Blue")
Set-Format -WorkSheet $excel.SEKRates -Range "A15:A17" -Bold -Height 50 -AutoSize
Set-ExcelRange -WorkSheet $excel.SEKRates -Range "A15:A17" -Bold -Height 50 -AutoSize
$v = @"
High - Red
@@ -94,6 +94,6 @@ Low - Green
Negative - Blue
"@
Set-Format -WorkSheet $excel.SEKRates -Range S17 -Value $v -WrapText -Width 20 -HorizontalAlignment Center -VerticalAlignment Center
Set-ExcelRange -WorkSheet $excel.SEKRates -Range S17 -Value $v -WrapText -Width 20 -HorizontalAlignment Center -VerticalAlignment Center
Close-ExcelPackage $excel -Show

View File

@@ -6,7 +6,7 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
Remove-Item "$env:temp\functions.xlsx" -ErrorAction SilentlyContinue
$(
New-PSItem 12001 Nails 37 3.99 =C2*D2 (echo ID Product Quantity Price Total)
New-PSItem 12001 Nails 37 3.99 =C2*D2 @("ID", "Product", "Quantity", "Price", "Total")
New-PSItem 12002 Hammer 5 12.10 =C3*D3
New-PSItem 12003 Saw 12 15.37 =C4*D4
New-PSItem 12010 Drill 20 8 =C5*D5

View File

@@ -3,7 +3,7 @@ try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
Remove-Item "$env:temp\functions.xlsx" -ErrorAction SilentlyContinue
$(
New-PSItem =2%/12 60 500000 "=pmt(rate,nper,pv)" (echo rate nper pv pmt)
New-PSItem =2%/12 60 500000 "=pmt(rate,nper,pv)" @("rate", "nper", "pv", "pmt")
New-PSItem =3%/12 60 500000 "=pmt(rate,nper,pv)"
New-PSItem =4%/12 60 500000 "=pmt(rate,nper,pv)"
New-PSItem =5%/12 60 500000 "=pmt(rate,nper,pv)"

View File

@@ -7,13 +7,10 @@ function Get-StockInfo {
)
$xlfile = "$env:TEMP\stocks.xlsx"
rm $xlfile -ErrorAction Ignore
Remove-Item -Path $xlfile -ErrorAction Ignore
$result = Invoke-RestMethod "https://api.iextrading.com/1.0/stock/market/batch?symbols=$($symbols)&types=quote&last=1"
$symbolCount = $symbols.Split(",").count
$ecd = New-ExcelChartDefinition -Row 1 -Column 1 -SeriesHeader $dataPlot `
-XRange symbol -YRange $dataPlot `
-Title "$($dataPlot)`r`n As Of $((Get-Date).ToShortDateString())"

View File

@@ -1,7 +1,7 @@
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
$xlfilename=".\test.xlsx"
rm $xlfilename -ErrorAction Ignore
Remove-Item $xlfilename -ErrorAction Ignore
$ConditionalText = @()
$ConditionalText += New-ConditionalText -Range "C:C" -Text failed -BackgroundColor red -ConditionalTextColor black
@@ -26,12 +26,12 @@ $sheet1 = $xlPkg.Workbook.Worksheets["sheet1"]
$sheet1.View.ShowGridLines = $false
$sheet1.View.ShowHeaders = $false
Set-Format -Address $sheet1.Cells["A:A"] -AutoSize
Set-Format -Address $sheet1.Cells["B:D"] -WrapText
Set-ExcelRange -Address $sheet1.Cells["A:A"] -AutoSize
Set-ExcelRange -Address $sheet1.Cells["B:D"] -WrapText
$sheet1.InsertColumn(1, 1)
Set-Format -Address $sheet1.Cells["A:A"] -Width 5
Set-ExcelRange -Address $sheet1.Cells["A:A"] -Width 5
Set-Format -Address $sheet1.Cells["B1:E1"] -HorizontalAlignment Center -BorderBottom Thick -BorderColor Cyan
Set-ExcelRange -Address $sheet1.Cells["B1:E1"] -HorizontalAlignment Center -BorderBottom Thick -BorderColor Cyan
Close-ExcelPackage $xlPkg -Show

View File

@@ -1,4 +1,6 @@
function Show-PesterResults {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="No suitable singular")]
Param()
$xlfilename = ".\test.xlsx"
Remove-Item $xlfilename -ErrorAction Ignore

View File

@@ -1,4 +1,5 @@
function Test-APIReadXls {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="False Positive")]
param(
[parameter(Mandatory)]
$XlFilename,

View File

@@ -1,12 +1,12 @@
# To ship, is to choose
# To ship, is to choose
#ipmo .\ImportExcel.psd1 -Force
$pt=[ordered]@{}
$pt.ServiceInfo=@{
$pt.ServiceInfo=@{
SourceWorkSheet='Services'
PivotRows = "Status"
PivotRows = "Status"
PivotData= @{'Status'='count'}
IncludePivotChart=$true
ChartType='BarClustered3D'
@@ -14,7 +14,7 @@ $pt.ServiceInfo=@{
$pt.ProcessInfo=@{
SourceWorkSheet='Processes'
PivotRows = "Company"
PivotRows = "Company"
PivotData= @{'Company'='count'}
IncludePivotChart=$true
ChartType='PieExploded3D'
@@ -24,7 +24,7 @@ $gsv=Get-Service | Select-Object status, Name, displayName, starttype
$ps=Get-Process | Select-Object Name,Company, Handles
$file = "c:\temp\testPT.xlsx"
rm $file -ErrorAction Ignore
Remove-Item $file -ErrorAction Ignore
$gsv| Export-Excel -Path $file -AutoSize -WorkSheetname Services
$ps | Export-Excel -Path $file -AutoSize -WorkSheetname Processes -PivotTableDefinition $pt -Show
$ps | Export-Excel -Path $file -AutoSize -WorkSheetname Processes -PivotTableDefinition $pt -Show

View File

@@ -32,7 +32,7 @@ End Function
$module = $wb.VbaProject.Modules.AddModule("PSExcelModule")
$module.Code = $code
Set-Format -WorkSheet $sheet -Range "h7" -Formula "HelloWorld()" -AutoSize
Set-Format -WorkSheet $sheet -Range "h8" -Formula "DoSum()" -AutoSize
Set-ExcelRange -WorkSheet $sheet -Range "h7" -Formula "HelloWorld()" -AutoSize
Set-ExcelRange -WorkSheet $sheet -Range "h8" -Formula "DoSum()" -AutoSize
Close-ExcelPackage $Excel -Show

View File

@@ -1,4 +1,6 @@
#Requires -Modules Pester
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
param()
if (-not (get-command Import-Excel -ErrorAction SilentlyContinue)) {
Import-Module $PSScriptRoot\..\ImportExcel.psd1
}

View File

@@ -1,3 +1,6 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
param()
Describe "Copy-Worksheet" {
$path1 = "TestDrive:\Test1.xlsx"
$path2 = "TestDrive:\Test2.xlsx"
@@ -94,7 +97,7 @@ Describe "Copy-Worksheet" {
Remove-Item $xlfile -ErrorAction SilentlyContinue
Remove-Item $xlfileArchive -ErrorAction SilentlyContinue
$sheets = echo 1.1.2019 1.2.2019 1.3.2019 1.4.2019 1.5.2019
$sheets = "1.1.2019", "1.2.2019", "1.3.2019", "1.4.2019", "1.5.2019"
$sheets | ForEach-Object {
"Hello World" | Export-Excel $xlfile -WorksheetName $_
@@ -102,7 +105,7 @@ Describe "Copy-Worksheet" {
}
it "Should copy and remove sheets " {
$targetSheets = echo 1.1.2019 1.4.2019
$targetSheets = "1.1.2019", "1.4.2019"
$targetSheets | ForEach-Object {
Copy-ExcelWorkSheet -SourceWorkbook $xlfile -DestinationWorkbook $xlfileArchive -SourceWorkSheet $_ -DestinationWorkSheet $_
@@ -122,7 +125,7 @@ Describe "Copy-Worksheet" {
Remove-Item $xlfile -ErrorAction SilentlyContinue
Remove-Item $xlfileArchive -ErrorAction SilentlyContinue
$sheets = echo 1.1.2019 1.2.2019 1.3.2019 1.4.2019 1.5.2019
$sheets = "1.1.2019", "1.2.2019", "1.3.2019", "1.4.2019", "1.5.2019"
$sheets | ForEach-Object {
"Hello World" | Export-Excel $xlfile -WorksheetName $_

View File

@@ -1,5 +1,7 @@
#Requires -Modules Pester
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidAssignmentToAutomaticVariable", "", Justification='Sets IsWindows on pre-6.0 only')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
param()
if (-not (get-command Import-Excel -ErrorAction SilentlyContinue)) {
Import-Module $PSScriptRoot\..\ImportExcel.psd1
}
@@ -20,7 +22,7 @@ Describe ExportExcel {
$path = "TestDrive:\test.xlsx"
Remove-item -Path $path -ErrorAction SilentlyContinue
#Test with a maximum of 100 processes for speed; export all properties, then export smaller subsets.
$processes = Get-Process | where {$_.StartTime} | Select-Object -first 100 -Property * -excludeProperty Parent
$processes = Get-Process | Where-Object {$_.StartTime} | Select-Object -First 100 -Property * -ExcludeProperty Parent
$propertyNames = $Processes[0].psobject.properties.name
$rowcount = $Processes.Count
$Processes | Export-Excel $path #-show
@@ -371,7 +373,7 @@ Describe ExportExcel {
$path = "TestDrive:\test.xlsx"
Remove-item -Path $path -ErrorAction SilentlyContinue
#Test -ConditionalText with a single conditional spec.
Write-Output 489 668 299 777 860 151 119 497 234 788 | Export-Excel -Path $path -ConditionalText $ct
489, 668, 299, 777, 860, 151, 119, 497, 234, 788 | Export-Excel -Path $path -ConditionalText $ct
it "Created a new file " {
Test-Path -Path $path -ErrorAction SilentlyContinue | Should be $true
@@ -612,7 +614,7 @@ Describe ExportExcel {
Get-Process | Select-Object -last 10 -Property Name, cpu, pm, handles, company | Export-Excel -Path $path -AutoNameRange -WorkSheetname NoOffset -Append -Numberformat 'Number'
$Excel = Open-ExcelPackage $path
$dataWs = $Excel.Workbook.Worksheets["NoOffset"]
#table should be 20 rows + header after extending the data. CPU range should be 1x20
it "Created a new sheet and auto-extended a table and explicitly extended named ranges " {
$dataWs.Tables["ProcTab"].Address.Address | Should be "A1:E21"
$dataWs.Names["CPU"].Rows | Should be 20

View File

@@ -1,4 +1,6 @@
$scriptPath = Split-Path -Path $MyInvocation.MyCommand.path -Parent
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
param()
$scriptPath = Split-Path -Path $MyInvocation.MyCommand.path -Parent
$dataPath = Join-Path -Path $scriptPath -ChildPath "First10Races.csv"
$WarningAction = "SilentlyContinue"

View File

@@ -5,17 +5,17 @@ Describe "Import-Excel on a sheet with no headings" {
$xl = "" | export-excel $xlfile -PassThru
Set-Format -WorkSheet $xl.Sheet1 -Range A1 -Value 'A'
Set-Format -WorkSheet $xl.Sheet1 -Range B1 -Value 'B'
Set-Format -WorkSheet $xl.Sheet1 -Range C1 -Value 'C'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range A1 -Value 'A'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range B1 -Value 'B'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range C1 -Value 'C'
Set-Format -WorkSheet $xl.Sheet1 -Range A2 -Value 'D'
Set-Format -WorkSheet $xl.Sheet1 -Range B2 -Value 'E'
Set-Format -WorkSheet $xl.Sheet1 -Range C2 -Value 'F'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range A2 -Value 'D'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range B2 -Value 'E'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range C2 -Value 'F'
Set-Format -WorkSheet $xl.Sheet1 -Range A3 -Value 'G'
Set-Format -WorkSheet $xl.Sheet1 -Range B3 -Value 'H'
Set-Format -WorkSheet $xl.Sheet1 -Range C3 -Value 'I'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range A3 -Value 'G'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range B3 -Value 'H'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range C3 -Value 'I'
Close-ExcelPackage $xl
}
@@ -160,20 +160,20 @@ Describe "Import-Excel on a sheet with no headings" {
$xlfile = "TestDrive:\testImportExcelSparse.xlsx"
$xl = "" | export-excel $xlfile -PassThru
Set-Format -WorkSheet $xl.Sheet1 -Range A1 -Value 'Chuck'
Set-Format -WorkSheet $xl.Sheet1 -Range B1 -Value ''
Set-Format -WorkSheet $xl.Sheet1 -Range C1 -Value 'Norris'
Set-Format -WorkSheet $xl.Sheet1 -Range D1 -Value 'California'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range A1 -Value 'Chuck'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range B1 -Value ''
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range C1 -Value 'Norris'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range D1 -Value 'California'
Set-Format -WorkSheet $xl.Sheet1 -Range A2 -Value ''
Set-Format -WorkSheet $xl.Sheet1 -Range B2 -Value ''
Set-Format -WorkSheet $xl.Sheet1 -Range C2 -Value ''
Set-Format -WorkSheet $xl.Sheet1 -Range D2 -Value ''
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range A2 -Value ''
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range B2 -Value ''
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range C2 -Value ''
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range D2 -Value ''
Set-Format -WorkSheet $xl.Sheet1 -Range A3 -Value 'Jean-Claude'
Set-Format -WorkSheet $xl.Sheet1 -Range B3 -Value ''
Set-Format -WorkSheet $xl.Sheet1 -Range C3 -Value 'Vandamme'
Set-Format -WorkSheet $xl.Sheet1 -Range D3 -Value 'Brussels'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range A3 -Value 'Jean-Claude'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range B3 -Value ''
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range C3 -Value 'Vandamme'
Set-ExcelRange -WorkSheet $xl.Sheet1 -Range D3 -Value 'Brussels'
Close-ExcelPackage $xl

View File

@@ -1,4 +1,6 @@
if (-not (get-command Import-Excel -ErrorAction SilentlyContinue)) {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
Param()
if (-not (get-command Import-Excel -ErrorAction SilentlyContinue)) {
Import-Module $PSScriptRoot\..\..\ImportExcel.psd1
}
Describe "Tests" {

View File

@@ -1,3 +1,5 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
Param()
Describe "Exporting with -Inputobject, table handling, Send-SQL-Data. Checking Import -asText" {
BeforeAll {
$path = "TestDrive:\Results.xlsx"

View File

@@ -1,4 +1,6 @@
$data1 = ConvertFrom-Csv -InputObject @"
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
param()
$data1 = ConvertFrom-Csv -InputObject @"
ID,Product,Quantity,Price,Total
12001,Nails,37,3.99,147.63
12002,Hammer,5,12.10,60.5

View File

@@ -1,3 +1,5 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingCmdletAliases','',Justification='Testing for presence of alias')]
param()
$path = "TestDrive:\test.xlsx"
describe "Consistent passing of ranges." {
Context "Conditional Formatting" {

View File

@@ -1,3 +1,8 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingCmdletAliases','',Justification='Testing for presence of alias')]
param()
$path = "TestDrive:\test.xlsx"
$data = ConvertFrom-Csv -InputObject @"

View File

@@ -1,3 +1,5 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
param()
$data = ConvertFrom-Csv -InputObject @"
ID,Product,Quantity,Price
12001,Nails,37,3.99

View File

@@ -6,7 +6,7 @@ function ConvertFrom-ExcelColumnName {
ForEach-Object {
$sum*=26
$sum+=[char]$_.tostring().toupper()-[char]'A'+1
}
}
$sum
}