mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Merge pull request #729 from jhoneill/master
Fix for #720, plus some linting - #730 Send-SQLDataToExcel -Append // The last row of data is overwritten by a header - #720 Incorrect table when supplying DataTable with zero rows
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
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 'Tab 1' -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$xlSourcefile = "$env:TEMP\Source.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
Remove-Item temp.xlsx -ErrorAction Ignore
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
Remove-Item temp.xlsx -ErrorAction Ignore
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
Remove-Item -Path Tools.xlsx
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
function plot {
|
||||
param(
|
||||
@@ -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 `$(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$file = "$env:temp\conditionalTextFormatting.xlsx"
|
||||
Remove-Item $file -ErrorAction Ignore
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
#Define a "Contains blanks" rule. No format is specified so it default to dark-red text on light-pink background.
|
||||
$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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$path = "$env:temp\test.xlsx"
|
||||
Remove-Item -Path $path -ErrorAction Ignore
|
||||
@@ -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
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = "$env:TEMP\testExport.xlsx"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
Remove-Item "$env:TEMP\testExport.xlsx" -ErrorAction Ignore
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = ".\testExport.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = ".\testExport.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = ".\testExport.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = ".\testExport.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = ".\testExport.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = ".\testExport.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = ".\testExport.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = ".\testExport.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = ".\testExport.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = ".\testExport.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = ".\testExport.xlsx"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
Remove-Item -Path .\test.xlsx -ErrorAction Ignore
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = ".\testExport.xlsx"
|
||||
Remove-Item $f -ErrorAction Ignore
|
||||
@@ -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)
|
||||
) |
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
Remove-Item -Path .\test.xlsx -ErrorAction Ignore
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
ConvertFrom-ExcelToSQLInsert People .\testSQLGen.xlsx
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$f = "$env:temp\dashboard.xlsx"
|
||||
Remove-Item $f -ErrorAction Ignore
|
||||
@@ -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
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* Add .01 in column F
|
||||
#>
|
||||
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$path = "$Env:TEMP\DataValidation.xlsx"
|
||||
Remove-Item $path -ErrorAction SilentlyContinue
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
ConvertFrom-ExcelToSQLInsert -TableName "Movies" -Path ".\Movies.xlsx" -ConvertEmptyStringsToNull
|
||||
''
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
param ($fibonacciDigits=10)
|
||||
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$file = "fib.xlsx"
|
||||
Remove-Item "fib.xlsx" -ErrorAction Ignore
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$xlfile = "$env:temp\testFmt.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$xlfile = "$env:temp\testFmt.xlsx"
|
||||
Remove-Item $xlfile -ErrorAction Ignore
|
||||
@@ -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,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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
@"
|
||||
site,link
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
|
||||
Import-Html "http://en.wikipedia.org/wiki/Demographics_of_India" 4
|
||||
@@ -1,3 +1,3 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
Import-Html "http://www.science.co.il/PTelements.asp" 1
|
||||
@@ -1,3 +1,3 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
Import-Html "https://en.wikipedia.org/wiki/List_of_Star_Trek:_The_Original_Series_episodes" 2
|
||||
@@ -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 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$xlfile = "$env:temp\AllSales.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
ColumnChart -Title "Central Limit Theorem" -NoLegend ($(
|
||||
for ($i = 1; $i -le 500; $i++) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Sum up handles by company
|
||||
# Show the Pie Chart
|
||||
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
PieChart -Title "Total Handles by Company" `
|
||||
(Invoke-Sum (Get-Process | Where-Object company) company handles)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# Sum up PM by company
|
||||
# Show the Pie Chart
|
||||
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
PieChart -Title "Total PM by Company" `
|
||||
(Invoke-Sum (Get-Process|Where-Object company) company pm)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
BarChart (.\TargetData.ps1) "A BarChart"
|
||||
@@ -1,3 +1,3 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
ColumnChart (.\TargetData.ps1) "A ColumnChart"
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
PieChart (.\TargetData.ps1) "A PieChart"
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$xlFile = "$env:TEMP\mw.xlsx"
|
||||
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$xlfile = "$env:TEMP\testThis.xlsx"
|
||||
Remove-Item $xlfile -ErrorAction Ignore
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
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]) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$file = "$env:TEMP\disks.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$file = "$env:temp\disks.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$file = "disks.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$file = "disks.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$file = "disks.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$file = "disks.xlsx"
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$file = "$env:Temp\sales.xlsx"
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$ExcelParams = @{
|
||||
Path = "$env:TEMP\test1.xlsx"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$xlFile="$env:TEMP\testPivot.xlsx"
|
||||
Remove-Item $xlFile -ErrorAction Ignore
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$plt = New-Plot
|
||||
$plt.Plot((Get-Range 0 5 .02|Foreach-Object {[math]::Cos(2*[math]::pi*$_)}))
|
||||
|
||||
@@ -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
|
||||
@@ -1,4 +1,4 @@
|
||||
$xlfile = "$env:TEMP\MultipleSheets.xlsx"
|
||||
|
||||
.\GenerateXlsx.ps1 $xlfile
|
||||
.\Get-ExcelSheets.ps1 $xlfile
|
||||
.\GenerateXlsx.ps1 $xlfile
|
||||
.\Get-ExcelSheets.ps1 $xlfile
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$sql = @"
|
||||
SELECT rootfile.baseName , rootfile.extension , Image.fileWidth AS width , image.fileHeight AS height ,
|
||||
@@ -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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#requires -modules "getSql"
|
||||
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
#download f1Results from https://1drv.ms/f/s!AhfYu7-CJv4egbt5FD7Cdxi8jSz3aQ and update the path below
|
||||
Get-SQL -Session f1 -Excel -Connection C:\Users\mcp\OneDrive\Public\F1\f1Results.xlsx -showtables -Verbose
|
||||
|
||||
@@ -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
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$path = "$env:TEMP\testBackgroundColor.xlsx"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try { . $PSScriptRoot\..\..\LoadPSD1.ps1 } catch { }
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$xlfile = "$env:TEMP\SalesByQuarter.xlsx"
|
||||
Remove-Item $xlfile -ErrorAction SilentlyContinue
|
||||
@@ -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"] )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try { . $PSScriptRoot\..\..\LoadPSD1.ps1 } catch { }
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
class data {
|
||||
[datetime]$Date
|
||||
@@ -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
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
|
||||
#. ..\New-PSItem.ps1
|
||||
@@ -6,7 +6,7 @@ try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
Remove-Item .\testFormula.xlsx -ErrorAction Ignore
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
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)"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
Remove-Item "$env:temp\hyperlink.xlsx" -ErrorAction SilentlyContinue
|
||||
|
||||
|
||||
@@ -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,4 +1,4 @@
|
||||
try { . $PSScriptRoot\..\..\LoadPSD1.ps1 } catch { }
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$xlfile = "$env:TEMP\test.xlsx"
|
||||
Remove-Item $xlfile -ErrorAction SilentlyContinue
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# https://raw.githubusercontent.com/dfinke/ImportExcel/master/images/NewExcelStyle.png
|
||||
try { . $PSScriptRoot\..\..\LoadPSD1.ps1 } catch { }
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$xlfile = "$env:TEMP\test.xlsx"
|
||||
Remove-Item $xlfile -ErrorAction SilentlyContinue
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$xlfile = "$env:Temp\testData.xlsx"
|
||||
Remove-Item $xlfile -ErrorAction SilentlyContinue
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
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,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
. $PSScriptRoot\TestAPIReadXls.ps1
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
$file = "C:\Temp\test.xlsx"
|
||||
|
||||
|
||||
@@ -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,4 @@
|
||||
try {. $PSScriptRoot\..\..\LoadPSD1.ps1} catch {}
|
||||
try {Import-Module $PSScriptRoot\..\..\ImportExcel.psd1} catch {throw ; return}
|
||||
|
||||
|
||||
. .\ConvertExcelToImageFile.ps1
|
||||
|
||||
@@ -422,11 +422,9 @@
|
||||
[OutputType([OfficeOpenXml.ExcelPackage])]
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingPlainTextForPassword", "")]
|
||||
Param(
|
||||
|
||||
[Parameter(ParameterSetName = 'Default', Position = 0)]
|
||||
[String]$Path,
|
||||
[Parameter(Mandatory = $true, ParameterSetName = "Package")]
|
||||
|
||||
[OfficeOpenXml.ExcelPackage]$ExcelPackage,
|
||||
[Parameter(ValueFromPipeline = $true)]
|
||||
[Alias('TargetData')]
|
||||
@@ -462,8 +460,6 @@
|
||||
[Switch]$FreezeFirstColumn,
|
||||
[Switch]$FreezeTopRowFirstColumn,
|
||||
[Int[]]$FreezePane,
|
||||
|
||||
|
||||
[Switch]$AutoFilter,
|
||||
[Switch]$BoldTopRow,
|
||||
[Switch]$NoHeader,
|
||||
@@ -473,12 +469,9 @@
|
||||
else { $true }
|
||||
})]
|
||||
[String]$RangeName,
|
||||
|
||||
|
||||
[Alias('Table')]
|
||||
$TableName,
|
||||
|
||||
|
||||
[OfficeOpenXml.Table.TableStyles]$TableStyle,
|
||||
[OfficeOpenXml.Table.TableStyles]$TableStyle = [OfficeOpenXml.Table.TableStyles]::Medium6,
|
||||
[Switch]$Barchart,
|
||||
[Switch]$PieChart,
|
||||
[Switch]$LineChart ,
|
||||
@@ -525,16 +518,18 @@
|
||||
#Open the file, get the worksheet, and decide where in the sheet we are writing, and if there is a number format to apply.
|
||||
try {
|
||||
$script:Header = $null
|
||||
if ($Append -and $ClearSheet) {throw "You can't use -Append AND -ClearSheet."}
|
||||
if ($Append -and $ClearSheet) {throw "You can't use -Append AND -ClearSheet." ; return}
|
||||
#To force -Now not to format as a table, allow $false in -TableName to be "No table"
|
||||
$TableName = if ($null -eq $TableName -or ($TableName -is [bool] -and $false -eq $TableName)) { $null } else {[String]$TableName}
|
||||
if ($PSBoundParameters.Keys.Count -eq 0 -Or $Now -or (-not $Path -and -not $ExcelPackage) ) {
|
||||
if ($Now -or (-not $Path -and -not $ExcelPackage) ) {
|
||||
if (-not $PSBoundParameters.ContainsKey("Path")) { $Path = [System.IO.Path]::GetTempFileName() -replace '\.tmp', '.xlsx' }
|
||||
if (-not $PSBoundParameters.ContainsKey("Show")) { $Show = $true }
|
||||
if (-not $PSBoundParameters.ContainsKey("AutoSize")) { $AutoSize = $true }
|
||||
#"Now" option will create a table, unless something passed in TableName/Table Style. False in TableName will block autocreation
|
||||
if (-not $PSBoundParameters.ContainsKey("TableName") -and
|
||||
-not $PSBoundParameters.ContainsKey("TableStyle") -and
|
||||
-not $AutoFilter) {
|
||||
$TableName = ''
|
||||
$TableName = '' # later rely on distinction between NULL and ""
|
||||
}
|
||||
}
|
||||
if ($ExcelPackage) {
|
||||
@@ -560,6 +555,7 @@
|
||||
$headerRange = $ws.Dimension.Address -replace "\d+$", $StartRow
|
||||
#using a slightly odd syntax otherwise header ends up as a 2D array
|
||||
$ws.Cells[$headerRange].Value | ForEach-Object -Begin {$Script:header = @()} -Process {$Script:header += $_ }
|
||||
$NoHeader = $true
|
||||
#if we did not get AutoNameRange, but headers have ranges of the same name make autoNameRange True, otherwise make it false
|
||||
if (-not $AutoNameRange) {
|
||||
$AutoNameRange = $true ; foreach ($h in $header) {if ($ws.names.name -notcontains $h) {$AutoNameRange = $false} }
|
||||
@@ -576,8 +572,10 @@
|
||||
}
|
||||
|
||||
#if we did not get a table name but there is a table which covers the active part of the sheet, set table name to that, and don't do anything with autofilter
|
||||
if ($null -eq $TableName -and $ws.Tables.Where({$_.address.address -eq $ws.dimension.address})) {
|
||||
$TableName = $ws.Tables.Where({$_.address.address -eq $ws.dimension.address},'First', 1).Name
|
||||
$existingTable = $ws.Tables.Where({$_.address.address -eq $ws.dimension.address},'First', 1)
|
||||
if ($null -eq $TableName -and $existingTable) {
|
||||
$TableName = $existingTable.Name
|
||||
$TableStyle = $existingTable.StyleName -replace "^TableStyle",""
|
||||
$AutoFilter = $false
|
||||
}
|
||||
#if we did not get $autofilter but a filter range is set and it covers the right area, set autofilter to true
|
||||
@@ -622,10 +620,39 @@
|
||||
catch {throw "Failed preparing to export to worksheet '$WorksheetName' to '$Path': $_"}
|
||||
#region Special case -inputobject passed a dataTable object
|
||||
<# If inputObject was passed via the pipeline it won't be visible until the process block, we will only see it here if it was passed as a parameter
|
||||
if it was passed it is a data table don't do foreach on it (slow) put the whole table in and set dates on date columns,
|
||||
if it is a data table don't do foreach on it (slow) - put the whole table in and set dates on date columns,
|
||||
set things up for the end block, and skip the process block #>
|
||||
if ($InputObject -is [System.Data.DataTable]) {
|
||||
$null = $ws.Cells[$row,$StartColumn].LoadFromDataTable($InputObject, (-not $noHeader) )
|
||||
if ($Append -and $ws.dimension) {
|
||||
$row ++
|
||||
$null = $ws.Cells[$row,$StartColumn].LoadFromDataTable($InputObject, $false )
|
||||
if ($TableName -or $PSBoundParameters.ContainsKey('TableStyle')) {
|
||||
Add-ExcelTable -Range $ws.Cells[$ws.Dimension] -TableName $TableName -TableStyle $TableStyle
|
||||
}
|
||||
}
|
||||
else {
|
||||
#Change TableName if $TableName is non-empty; don't leave caller with a renamed table!
|
||||
$orginalTableName = $InputObject.TableName
|
||||
if ($PSBoundParameters.ContainsKey("TableName")) {
|
||||
$InputObject.TableName = $TableName
|
||||
}
|
||||
while ($InputObject.TableName -in $pkg.Workbook.Worksheets.Tables.name) {
|
||||
Write-Warning "Table name $($InputObject.TableName) is not unique, adding '_' to it "
|
||||
$InputObject.TableName += "_"
|
||||
}
|
||||
#Insert as a table, if Tablestyle didn't arrive as a default, or $TableName non-null - even if empty
|
||||
if ($null -ne $TableName -or $PSBoundParameters.ContainsKey("TableStyle")) {
|
||||
$null = $ws.Cells[$row,$StartColumn].LoadFromDataTable($InputObject, (-not $noHeader),$TableStyle )
|
||||
# Workaround for EPPlus not marking the empty row on an empty table as dummy row.
|
||||
if ($InputObject.Rows.Count -eq 0) {
|
||||
($ws.Tables | Select-Object -Last 1).TableXml.table.SetAttribute('insertRow', 1)
|
||||
}
|
||||
}
|
||||
else {
|
||||
$null = $ws.Cells[$row,$StartColumn].LoadFromDataTable($InputObject, (-not $noHeader) )
|
||||
}
|
||||
$InputObject.TableName = $orginalTableName
|
||||
}
|
||||
foreach ($c in $InputObject.Columns.where({$_.datatype -eq [datetime]})) {
|
||||
Set-ExcelColumn -Worksheet $ws -Column ($c.Ordinal + $StartColumn) -NumberFormat 'Date-Time'
|
||||
}
|
||||
@@ -807,14 +834,11 @@
|
||||
if ($RangeName) { Add-ExcelName -Range $ws.Cells[$dataRange] -RangeName $RangeName}
|
||||
|
||||
#Allow table to be inserted by specifying Name, or Style or both; only process autoFilter if there is no table (they clash).
|
||||
if ($null -ne $TableName) {
|
||||
if ($PSBoundParameters.ContainsKey('TableStyle')) {
|
||||
Add-ExcelTable -Range $ws.Cells[$dataRange] -TableName $TableName -TableStyle $TableStyle
|
||||
if ($null -ne $TableName -or $PSBoundParameters.ContainsKey('TableStyle')) {
|
||||
#Already inserted Excel table if input was a DataTable
|
||||
if ($InputObject -isnot [System.Data.DataTable]) {
|
||||
Add-ExcelTable -Range $ws.Cells[$dataRange] -TableName $TableName -TableStyle $TableStyle
|
||||
}
|
||||
else {Add-ExcelTable -Range $ws.Cells[$dataRange] -TableName $TableName}
|
||||
}
|
||||
elseif ($PSBoundParameters.ContainsKey('TableStyle')) {
|
||||
Add-ExcelTable -Range $ws.Cells[$dataRange] -TableName "" -TableStyle $TableStyle
|
||||
}
|
||||
elseif ($AutoFilter) {
|
||||
try {
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
if($null -eq (Get-Module -ListAvailable ImportExcel) ) {
|
||||
Import-Module $PSScriptRoot\ImportExcel.psd1 -force
|
||||
}
|
||||
@@ -1,18 +1,20 @@
|
||||
#Requires -Modules Pester
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
|
||||
param()
|
||||
if (-not (get-command Import-Excel -ErrorAction SilentlyContinue)) {
|
||||
Import-Module $PSScriptRoot\..\ImportExcel.psd1
|
||||
}
|
||||
Describe "Compare Worksheet" {
|
||||
BeforeAll {
|
||||
if ($PSVersionTable.PSVersion.Major -gt 5) {
|
||||
<# if ($PSVersionTable.PSVersion.Major -gt 5) {
|
||||
It "GridView Support" {
|
||||
Set-ItResult -Pending -Because "Can't test grid view on V6 and later"
|
||||
}
|
||||
}
|
||||
else { Add-Type -AssemblyName System.Windows.Forms }
|
||||
else { Add-Type -AssemblyName System.Windows.Forms } #>
|
||||
. "$PSScriptRoot\Samples\Samples.ps1"
|
||||
Remove-Item -Path "TestDrive:\server*.xlsx"
|
||||
[System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property Name, RequiredServices, CanPauseAndContinue, CanShutdown, CanStop, DisplayName, DependentServices, MachineName
|
||||
[System.Collections.ArrayList]$s = Get-Service | Select-Object -first 25 -Property Name, RequiredServices, CanPauseAndContinue, CanShutdown, CanStop, DisplayName, DependentServices, MachineName
|
||||
$s | Export-Excel -Path TestDrive:\server1.xlsx
|
||||
#$s is a zero based array, excel rows are 1 based and excel has a header row so Excel rows will be 2 + index in $s
|
||||
$row4Displayname = $s[2].DisplayName
|
||||
@@ -177,8 +179,8 @@ Describe "Compare Worksheet" {
|
||||
$s2Sheet.Cells["F4"].Style.Font.Color.Rgb | Should beNullOrEmpty
|
||||
}
|
||||
AfterAll {
|
||||
# Close-ExcelPackage -ExcelPackage $xl1 -NoSave -Show
|
||||
# Close-ExcelPackage -ExcelPackage $xl2 -NoSave -Show
|
||||
Close-ExcelPackage -ExcelPackage $xl1 -NoSave # -Show
|
||||
Close-ExcelPackage -ExcelPackage $xl2 -NoSave # -Show
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,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
|
||||
@@ -657,7 +659,7 @@ Describe ExportExcel {
|
||||
#Catch warning
|
||||
$warnvar = $null
|
||||
#Test create two data pages; as part of adding the second give both their own pivot table, test -autosize switch
|
||||
Get-Service | Select-Object -Property Status, Name, DisplayName, StartType, CanPauseAndContinue | Export-Excel -Path $path -AutoSize -TableName "All Services" -TableStyle Medium1 -WarningVariable warnvar
|
||||
Get-Service | Select-Object -Property Status, Name, DisplayName, StartType, CanPauseAndContinue | Export-Excel -Path $path -AutoSize -TableName "All Services" -TableStyle Medium1 -WarningVariable warnvar -WarningAction SilentlyContinue
|
||||
Get-Process | Select-Object -Property Name, Company, Handles, CPU, VM | Export-Excel -Path $path -AutoSize -WorkSheetname 'sheet2' -TableName "Processes" -TableStyle Light1 -Title "Processes" -TitleFillPattern Solid -TitleBackgroundColor ([System.Drawing.Color]::AliceBlue) -TitleBold -TitleSize 22 -PivotTableDefinition $ptDef
|
||||
$Excel = Open-ExcelPackage $path
|
||||
$ws1 = $Excel.Workbook.Worksheets["Sheet1"]
|
||||
@@ -1004,7 +1006,7 @@ Describe ExportExcel {
|
||||
Remove-Item -Path $Path -ErrorAction SilentlyContinue
|
||||
$Processes = Get-Process | Select-Object -first 10 -Property Name, cpu, pm, handles, company
|
||||
|
||||
it "Default Set with Path".PadRight(87) {
|
||||
it "Allows the default parameter set with Path".PadRight(87) {
|
||||
$ExcelPackage = $Processes | Export-Excel -Path $Path -PassThru
|
||||
$Worksheet = $ExcelPackage.Workbook.Worksheets[1]
|
||||
|
||||
@@ -1013,7 +1015,7 @@ Describe ExportExcel {
|
||||
$Worksheet.Tables | Should BeNullOrEmpty
|
||||
$Worksheet.AutoFilterAddress | Should BeNullOrEmpty
|
||||
}
|
||||
it "ExcelPackage Set. Path and (ExcelPackage or Now) should throw".PadRight(87) {
|
||||
it "throws when the ExcelPackage is specified with either -path or -Now".PadRight(87) {
|
||||
$ExcelPackage = Export-Excel -Path $Path -PassThru
|
||||
{Export-Excel -ExcelPackage $ExcelPackage -Path $Path} | Should Throw 'Parameter set cannot be resolved using the specified named parameters'
|
||||
{Export-Excel -ExcelPackage $ExcelPackage -Now} | Should Throw 'Parameter set cannot be resolved using the specified named parameters'
|
||||
@@ -1039,9 +1041,9 @@ Describe ExportExcel {
|
||||
$ExcelPackage = $Processes | Export-Excel -Now -PassThru
|
||||
$Worksheet = $ExcelPackage.Workbook.Worksheets[1]
|
||||
|
||||
$ExcelPackage.File | Should BeLike ([IO.Path]::GetTempPath() + '*')
|
||||
$Worksheet.Tables[0].Name | Should Be 'Table1'
|
||||
$Worksheet.AutoFilterAddress | Should BeNullOrEmpty
|
||||
$ExcelPackage.File.FullName | Should BeLike ([IO.Path]::GetTempPath() + '*')
|
||||
$Worksheet.Tables[0].Name | Should Be 'Table1'
|
||||
$Worksheet.AutoFilterAddress | Should BeNullOrEmpty
|
||||
if ($isWindows) {
|
||||
$Worksheet.Column(5).Width | Should BeGreaterThan 9.5
|
||||
}
|
||||
|
||||
@@ -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,8 +1,11 @@
|
||||
Describe "Exporting with -Inputobject; table handling, Send SQL Data and import as " {
|
||||
[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"
|
||||
Remove-Item -Path $path -ErrorAction SilentlyContinue
|
||||
. "$PSScriptRoot\Samples\Samples.ps1"
|
||||
$path = "TestDrive:\Results.xlsx"
|
||||
$path2 = "TestDrive:\Results2.xlsx"
|
||||
Remove-Item -Path $path,$path2 -ErrorAction SilentlyContinue
|
||||
if (Test-path "$PSScriptRoot\Samples\Samples.ps1") {. "$PSScriptRoot\Samples\Samples.ps1"}
|
||||
$results = ((Get-Process) + (Get-Process -id $PID)) | Select-Object -last 10 -Property Name, cpu, pm, handles, StartTime
|
||||
$DataTable = [System.Data.DataTable]::new('Test')
|
||||
$null = $DataTable.Columns.Add('Name')
|
||||
@@ -10,15 +13,34 @@ Describe "Exporting with -Inputobject; table handling, Send SQL Data and import
|
||||
$null = $DataTable.Columns.Add('PM', [Long])
|
||||
$null = $DataTable.Columns.Add('Handles', [Int])
|
||||
$null = $DataTable.Columns.Add('StartTime', [DateTime])
|
||||
Send-SQLDataToExcel -path $path -DataTable $DataTable -WorkSheetname Sheet4 -force -TableName "Data" -WarningVariable WVOne -WarningAction SilentlyContinue
|
||||
Send-SQLDataToExcel -path $path -DataTable ([System.Data.DataTable]::new('Test2')) -WorkSheetname Sheet5 -force -WarningVariable wvTwo -WarningAction SilentlyContinue
|
||||
foreach ($r in $results) {
|
||||
$null = $DataTable.Rows.Add($r.name, $r.CPU, $R.PM, $r.Handles, $r.StartTime)
|
||||
}
|
||||
export-excel -Path $path -InputObject $results -WorksheetName Sheet1 -RangeName "Whole"
|
||||
export-excel -Path $path -InputObject $DataTable -WorksheetName Sheet2 -AutoNameRange
|
||||
Send-SQLDataToExcel -path $path -DataTable $DataTable -WorkSheetname Sheet3 -TableName "Data"
|
||||
$DataTable.Rows.Clear()
|
||||
Send-SQLDataToExcel -path $path -DataTable $DataTable -WorkSheetname Sheet4 -force -WarningVariable WVOne -WarningAction SilentlyContinue
|
||||
Send-SQLDataToExcel -path $path -DataTable ([System.Data.DataTable]::new('Test2')) -WorkSheetname Sheet5 -force -WarningVariable wvTwo -WarningAction SilentlyContinue
|
||||
$NowPkg = Export-Excel -InputObject $DataTable -PassThru
|
||||
$NowPath1 = $NowPkg.File.FullName
|
||||
Close-ExcelPackage $NowPkg
|
||||
$NowPkg = Export-Excel -InputObject $DataTable -PassThru -table:$false
|
||||
$NowPath2 = $NowPkg.File.FullName
|
||||
Close-ExcelPackage $NowPkg
|
||||
Export-Excel -Path $path -InputObject $results -WorksheetName Sheet1 -RangeName "Whole"
|
||||
Export-Excel -Path $path -InputObject $DataTable -WorksheetName Sheet2 -AutoNameRange
|
||||
Send-SQLDataToExcel -path $path -DataTable $DataTable -WorkSheetname Sheet3 -TableName "Data" -WarningVariable WVThree -WarningAction SilentlyContinue
|
||||
|
||||
Send-SQLDataToExcel -Path $path2 -DataTable $DataTable -WorksheetName Sheet1 -Append
|
||||
Send-SQLDataToExcel -Path $path2 -DataTable $DataTable -WorksheetName Sheet1 -Append
|
||||
|
||||
Send-SQLDataToExcel -Path $path2 -DataTable $DataTable -WorksheetName Sheet2 -Append -TableName "FirstLot" -TableStyle light7
|
||||
Send-SQLDataToExcel -Path $path2 -DataTable $DataTable -WorksheetName Sheet2 -Append
|
||||
|
||||
Send-SQLDataToExcel -Path $path2 -DataTable $DataTable -WorksheetName Sheet3 -Append
|
||||
Send-SQLDataToExcel -Path $path2 -DataTable $DataTable -WorksheetName Sheet3 -Append -TableName "SecondLot"
|
||||
|
||||
Send-SQLDataToExcel -Path $path2 -DataTable $DataTable -WorksheetName Sheet4 -Append
|
||||
Send-SQLDataToExcel -Path $path2 -DataTable $DataTable -WorksheetName Sheet4 -Append -TableStyle Dark5
|
||||
|
||||
|
||||
$excel = Open-ExcelPackage $path
|
||||
$sheet = $excel.Sheet1
|
||||
}
|
||||
@@ -61,6 +83,23 @@ Describe "Exporting with -Inputobject; table handling, Send SQL Data and import
|
||||
$sheet.Cells["E11"].Style.Numberformat.NumFmtID | should be 22
|
||||
}
|
||||
}
|
||||
|
||||
Context "'Now' Mode behavior" {
|
||||
$NowPkg = Open-ExcelPackage $NowPath1
|
||||
$sheet = $NowPkg.Sheet1
|
||||
it "Formatted data as a table by default " {
|
||||
$sheet.Tables.Count | should be 1
|
||||
}
|
||||
Close-ExcelPackage -NoSave $NowPkg
|
||||
Remove-Item $NowPath1
|
||||
$NowPkg = Open-ExcelPackage $NowPath2
|
||||
$sheet = $NowPkg.Sheet1
|
||||
it "Did not data as a table when table:`$false was used " {
|
||||
$sheet.Tables.Count | should be 0
|
||||
}
|
||||
Close-ExcelPackage -NoSave $NowPkg
|
||||
Remove-Item $NowPath2
|
||||
}
|
||||
$sheet = $excel.Sheet3
|
||||
Context "Table of processes via Send-SQLDataToExcel" {
|
||||
it "Put the correct data rows and columns into the sheet " {
|
||||
@@ -72,12 +111,15 @@ Describe "Exporting with -Inputobject; table handling, Send SQL Data and import
|
||||
}
|
||||
it "Created a table " {
|
||||
$sheet.Tables.count | should be 1
|
||||
$sheet.Tables[0].Name | should be "Data"
|
||||
$sheet.Tables[0].Columns[4].name | should be "StartTime"
|
||||
}
|
||||
it "Formatted date fields with date type " {
|
||||
$sheet.Cells["E11"].Style.Numberformat.NumFmtID | should be 22
|
||||
}
|
||||
it "Handled two data tables with the same name " {
|
||||
$sheet.Tables[0].Name | should be "Data_"
|
||||
$wvThree[0] | should match "is not unique"
|
||||
}
|
||||
}
|
||||
$Sheet = $excel.Sheet4
|
||||
Context "Zero-row Data Table sent with Send-SQLDataToExcel -Force" {
|
||||
@@ -87,17 +129,56 @@ Describe "Exporting with -Inputobject; table handling, Send SQL Data and import
|
||||
$sheet.cells["A1"].Value | should be "Name"
|
||||
$sheet.cells["E1"].Value | should be "StartTime"
|
||||
$sheet.cells["A3"].Value | should beNullOrEmpty
|
||||
$wvone | should not beNullOrEmpty
|
||||
$wvone[0] | should match "Zero"
|
||||
}
|
||||
it "Applied table formatting " {
|
||||
$sheet.Tables.Count | should be 1
|
||||
$sheet.Tables[0].Name | should be "Data"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
$Sheet = $excel.Sheet5
|
||||
Context "Zero-column Data Table handled by Send-SQLDataToExcel -Force" {
|
||||
it "Put Created a blank Sheet and raised a warning " {
|
||||
it "Created a blank Sheet and raised a warning " {
|
||||
$sheet.Dimension | should beNullOrEmpty
|
||||
$wvTwo | should not beNullOrEmpty
|
||||
}
|
||||
|
||||
}
|
||||
Close-ExcelPackage $excel
|
||||
$excel = Open-ExcelPackage $path2
|
||||
Context "Send-SQLDataToExcel -append works correctly" {
|
||||
it "Works without table settings " {
|
||||
$excel.sheet1.Dimension.Address | should be "A1:E21"
|
||||
$excel.sheet1.cells[1,1].value | should be "Name"
|
||||
$excel.sheet1.cells[12,1].value | should be $excel.sheet1.cells[2,1].value
|
||||
$excel.sheet1.Tables.count | should be 0
|
||||
}
|
||||
it "Extends an existing table when appending " {
|
||||
$excel.sheet2.Dimension.Address | should be "A1:E21"
|
||||
$excel.sheet2.cells[1,2].value | should be "CPU"
|
||||
$excel.sheet2.cells[13,2].value | should be $excel.sheet2.cells[3,2].value
|
||||
$excel.sheet2.Tables.count | should be 1
|
||||
$excel.sheet2.Tables[0].name | should be "FirstLot"
|
||||
$excel.sheet2.Tables[0].StyleName | should be "TableStyleLight7"
|
||||
}
|
||||
it "Creates a new table by name when appending " {
|
||||
$excel.sheet3.cells[1,3].value | should be "PM"
|
||||
$excel.sheet3.cells[14,3].value | should be $excel.sheet3.cells[4,3].value
|
||||
$excel.sheet3.Tables.count | should be 1
|
||||
$excel.sheet3.Tables[0].name | should be "SecondLot"
|
||||
$excel.sheet3.Tables[0].StyleName | should be "TableStyleMedium6"
|
||||
}
|
||||
it "Creates a new table by style when appending " {
|
||||
$excel.sheet4.cells[1,4].value | should be "Handles"
|
||||
$excel.sheet4.cells[15,4].value | should be $excel.sheet4.cells[5,4].value
|
||||
$excel.sheet4.Tables.count | should be 1
|
||||
$excel.sheet4.Tables[0].name | should be "Table1"
|
||||
$excel.sheet4.Tables[0].StyleName | should be "TableStyleDark5"
|
||||
}
|
||||
}
|
||||
|
||||
Close-ExcelPackage $excel
|
||||
Context "Import As Text returns text values" {
|
||||
$x = import-excel $path -WorksheetName sheet3 -AsText StartTime,hand* | Select-Object -last 1
|
||||
|
||||
@@ -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" {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user