mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Major linting push
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
@@ -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 `$(
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
) |
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
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 {
|
||||
|
||||
|
||||
@@ -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 |
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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/'
|
||||
|
||||
@@ -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]) {
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
## 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,
|
||||
@@ -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,10 +180,10 @@ 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 {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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"] )
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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)"
|
||||
|
||||
@@ -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())"
|
||||
|
||||
@@ -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
|
||||
@@ -1,4 +1,6 @@
|
||||
function Show-PesterResults {
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="No suitable singular")]
|
||||
Param()
|
||||
$xlfilename = ".\test.xlsx"
|
||||
Remove-Item $xlfilename -ErrorAction Ignore
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
function Test-APIReadXls {
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseSingularNouns", "", Justification="False Positive")]
|
||||
param(
|
||||
[parameter(Mandatory)]
|
||||
$XlFilename,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 $_
|
||||
|
||||
@@ -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,9 +614,9 @@ 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:E11"
|
||||
$dataWs.Tables["ProcTab"].Address.Address | Should be "A1:E21"
|
||||
$dataWs.Names["CPU"].Rows | Should be 20
|
||||
$dataWs.Names["CPU"].Columns | Should be 1
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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" {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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" {
|
||||
|
||||
@@ -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 @"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user