fix naming consitency (case mostly)

This commit is contained in:
jhoneill
2019-11-25 01:01:55 +00:00
parent f6c66e21a7
commit feb493e397
56 changed files with 249 additions and 214 deletions

View File

@@ -0,0 +1,44 @@

Function Test-SingleFunction {
param (
[parameter(ValueFromPipeline=$true)]
$path )
begin {
Push-Location "C:\Users\mcp\Documents\GitHub\ImportExcel"
$exportedFunctions = (Import-LocalizedData -FileName "ImportExcel.psd1").functionsToExport
Pop-Location
$reg = [Regex]::new(@"
function\s*[-\w]+\s*{ # The function name and opening '{'
(?:
[^{}]+ # Match all non-braces
|
(?<open> { ) # Match '{', and capture into 'open'
|
(?<-open> } ) # Match '}', and delete the 'open' capture
)*
(?(open)(?!)) # Fails if 'open' stack isn't empty
} # Functions closing '}'
"@, 33) # 33 = ignore case and white space.
}#
process {
$item = Get-item $Path
$name = $item.Name -replace "\.\w+$",""
Write-Verbose $name
$file = Get-Content $item -Raw
$m = $reg.Matches($file)
#based on https://stackoverflow.com/questions/7898310/using-regex-to-balance-match-parenthesis
if ($m.Count -eq 0) {return "Could not find $name function in $($item.name)"}
elseif ($m.Count -ge 2) {return "Multiple functions in $($item.name)"}
elseif ($exportedFunctions -cnotcontains $name) {return "$name not exported (or in the wrong case)"}
elseif ($m[0] -cnotmatch "^\w+\s+$name") {return "function $name in wrong case"}
elseif ($m[0] -inotmatch "^function\s*$name\s*{(\s*<\#.*?\#>|\s*\[.*?\])*\s*param") {return "No param block in $name"}
elseif ($m[0] -inotmatch "\[cmdletbinding\(" -and
$m[0] -inotmatch "\[parameter\(" ) {return "$name has is not an advanced function"}
elseif (-not (& $Name -?).synopsis) {return "$name has no help"}
else {return "$name OK"}
}
}

View File

@@ -7,6 +7,6 @@ Remove-Item $xlSourcefile -ErrorAction Ignore
#Put some simple data in a worksheet and Get an excel package object to represent the file
$excel = 1..10 | Export-Excel $xlSourcefile -PassThru
#Add a new worksheet named 'NewSheet' and copying the sheet that was just made (Sheet1) to the new sheet
Add-WorkSheet -ExcelPackage $excel -WorkSheetname "NewSheet" -CopySource $excel.Workbook.Worksheets["Sheet1"]
Add-Worksheet -ExcelPackage $excel -WorkSheetname "NewSheet" -CopySource $excel.Workbook.Worksheets["Sheet1"]
#Save and open in Excel
Close-ExcelPackage -ExcelPackage $excel -Show

View File

@@ -22,9 +22,9 @@ Set-ExcelRange -Range $sheet.Column(4) -HorizontalAlignment Right -NFormat "#
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
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
Add-ConditionalFormatting -Worksheet $sheet -Range "G2:G1048576" -RuleType GreaterThan -ConditionValue "104857600" -ForeGroundColor Red
foreach ($c in 5..9) {Set-ExcelRange -Address $sheet.Column($c) -AutoFit }

View File

@@ -21,8 +21,8 @@ $data = $(
New-PSItem Westerly 120
New-PSItem SouthWest 118
)
# in this example instead of doing $variable = New-Conditional text <parameters> .... ; Export-excel -conditionalText $variable <other parameters>
# the syntax is used is Export-excel -conditionalText (New-Conditional text <parameters>) <other parameters>
# in this example instead of doing $variable = New-Conditional text <parameters> .... ; Export-excel -ConditionalText $variable <other parameters>
# the syntax is used is Export-excel -ConditionalText (New-Conditional text <parameters>) <other parameters>
#$data | Export-Excel $f -Show -AutoSize -ConditionalText (New-ConditionalText -ConditionalType AboveAverage)

View File

@@ -20,6 +20,6 @@ Dec,44,63,46
Export-Excel -Path .\test.xlsx -WorkSheetname Sheet1 -AutoNameRange -AutoSize -Title "Monthly Temperatures" -PassThru
$sheet = $excel.Workbook.Worksheets["Sheet1"]
Add-ConditionalFormatting -WorkSheet $sheet -Range "B1:D14" -DataBarColor CornflowerBlue
Add-ConditionalFormatting -Worksheet $sheet -Range "B1:D14" -DataBarColor CornflowerBlue
Close-ExcelPackage $excel -Show

View File

@@ -14,7 +14,7 @@ Jun,621
Export-Excel -Path .\test.xlsx -WorkSheetname Sheet1 -AutoNameRange -PassThru
$sheet = $excel.Workbook.Worksheets["Sheet1"]
Add-ConditionalFormatting -WorkSheet $sheet -Range "B1:B7" -DataBarColor LawnGreen
Add-ConditionalFormatting -Worksheet $sheet -Range "B1:B7" -DataBarColor LawnGreen
Set-ExcelRange -Address $sheet.Cells["A8"] -Value "Total"
Set-ExcelRange -Address $sheet.Cells["B8"] -Formula "=Sum(Sales)"

View File

@@ -39,7 +39,7 @@ $excelPackage = @('Chisel', 'Crowbar', 'Drill', 'Hammer', 'Nails', 'Saw', 'Screw
#region Creating a list using a PowerShell array
$ValidationParams = @{
WorkSheet = $excelPackage.sales
Worksheet = $excelPackage.sales
ShowErrorMessage = $true
ErrorStyle = 'stop'
ErrorTitle = 'Invalid Data'

View File

@@ -16,9 +16,9 @@ $pkg = $data | Export-Excel -Path $f -AutoSize -PassThru
$ws = $pkg.Workbook.Worksheets["Sheet1"]
Set-ExcelRange -WorkSheet $ws -Range "A2:C6" -BackgroundColor PeachPuff -FontColor Purple -FontSize 12 -Width 12
Set-ExcelRange -WorkSheet $ws -Range "D2:D6" -BackgroundColor WhiteSmoke -FontColor Orange -Bold -FontSize 12 -Width 12
Set-ExcelRange -WorkSheet $ws -Range "A1:D1" -BackgroundColor BlueViolet -FontColor Wheat -FontSize 12 -Width 12
Set-ExcelRange -WorkSheet $ws -Range "A:A" -Width 15
Set-ExcelRange -Worksheet $ws -Range "A2:C6" -BackgroundColor PeachPuff -FontColor Purple -FontSize 12 -Width 12
Set-ExcelRange -Worksheet $ws -Range "D2:D6" -BackgroundColor WhiteSmoke -FontColor Orange -Bold -FontSize 12 -Width 12
Set-ExcelRange -Worksheet $ws -Range "A1:D1" -BackgroundColor BlueViolet -FontColor Wheat -FontSize 12 -Width 12
Set-ExcelRange -Worksheet $ws -Range "A:A" -Width 15
Close-ExcelPackage -ExcelPackage $pkg -Show

View File

@@ -13,7 +13,7 @@ Timestamp,Tenant
10/29/2018 3:01:40.989,1
10/29/2018 3:01:50.545,1
10/29/2018 3:02:00.999,1
"@ | Select-Object @{n = 'Timestamp'; e = {get-date $_.timestamp}}, tenant, @{n = 'Bucket'; e = { - (get-date $_.timestamp).Second % 30}}
"@ | Select-Object @{n = 'Timestamp'; e = {Get-date $_.timestamp}}, tenant, @{n = 'Bucket'; e = { - (Get-date $_.timestamp).Second % 30}}
$f = "$env:temp\pivottest.xlsx"
Remove-Item $f -ErrorAction SilentlyContinue

View File

@@ -1,7 +1,7 @@
Remove-Item -Path "$env:temp\server*.xlsx" , "$env:temp\Combined*.xlsx" -ErrorAction SilentlyContinue
#Get a subset of services into $s and export them
[System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property *
[System.Collections.ArrayList]$s = Get-service | Select-Object -first 25 -Property *
$s | Export-Excel -Path $env:temp\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.

View File

@@ -1,7 +1,7 @@
Remove-Item -Path "$env:temp\server*.xlsx" , "$env:temp\Combined*.xlsx" -ErrorAction SilentlyContinue
#Get a subset of services into $s and export them
[System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property Name,DisplayName,StartType
[System.Collections.ArrayList]$s = Get-service | Select-Object -first 25 -Property Name,DisplayName,StartType
$s | Export-Excel -Path $env:temp\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.

View File

@@ -17,7 +17,7 @@ function New-CellData {
)
$setFormatParams = @{
WorkSheet = $ws
Worksheet = $ws
Range = $Range
NumberFormat = $Format
}

View File

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

View File

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

View File

@@ -41,8 +41,8 @@ Remove-Item $xlfile -ErrorAction SilentlyContinue
$excel = $data | Export-Excel $xlfile -WorksheetName SEKRates -AutoSize -PassThru
# Add a column sparkline for all currencies
Set-ExcelRange -WorkSheet $excel.SEKRates -Range "A2:A12" -NumberFormat "yyyy-mm-dd" -AutoSize
Set-ExcelRange -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-ExcelRange -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-ExcelRange -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-ExcelRange -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-ExcelRange -WorkSheet $excel.SEKRates -Range S17 -Value $v -WrapText -Width 20 -HorizontalAlignment Center -VerticalAlignment Center
Set-ExcelRange -Worksheet $excel.SEKRates -Range S17 -Value $v -WrapText -Width 20 -HorizontalAlignment Center -VerticalAlignment Center
Close-ExcelPackage $excel -Show

View File

@@ -5,7 +5,7 @@ function ConvertTo-PesterTest {
$WorksheetName = 'Sheet1'
)
$testFileName = "{0}.tests.ps1" -f (get-date).ToString("yyyyMMddHHmmss")
$testFileName = "{0}.tests.ps1" -f (Get-date).ToString("yyyyMMddHHmmss")
$records = Import-Excel $XlFilename

View File

@@ -6,7 +6,7 @@ function Test-APIReadXls {
$WorksheetName = 'Sheet1'
)
$testFileName = "{0}.tests.ps1" -f (get-date).ToString("yyyyMMddHHmmss")
$testFileName = "{0}.tests.ps1" -f (Get-date).ToString("yyyyMMddHHmmss")
$records = Import-Excel $XlFilename

View File

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

View File

@@ -3,7 +3,7 @@
[Parameter(Mandatory = $true, Position = 0)]
[Alias("Range")]
$Address ,
[OfficeOpenXml.ExcelWorksheet]$WorkSheet ,
[OfficeOpenXml.ExcelWorksheet]$Worksheet ,
[Parameter(Mandatory = $true, ParameterSetName = "NamedRule", Position = 1)]
[OfficeOpenXml.ConditionalFormatting.eExcelConditionalFormattingRuleType]$RuleType ,
[Parameter(ParameterSetName = "NamedRule")]
@@ -51,18 +51,18 @@
#Allow conditional formatting to work like Set-ExcelRange (with single ADDRESS parameter), split it to get worksheet and range of cells.
If ($Address -is [OfficeOpenXml.Table.ExcelTable]) {
$WorkSheet = $Address.Address.Worksheet
$Worksheet = $Address.Address.Worksheet
$Address = $Address.Address.Address
}
elseif ($Address.Address -and $Address.Worksheet -and -not $WorkSheet) { #Address is a rangebase or similar
$WorkSheet = $Address.Worksheet[0]
elseif ($Address.Address -and $Address.Worksheet -and -not $Worksheet) { #Address is a rangebase or similar
$Worksheet = $Address.Worksheet[0]
$Address = $Address.Address
}
elseif ($Address -is [String] -and $WorkSheet -and $WorkSheet.Names[$Address] ) { #Address is the name of a named range.
$Address = $WorkSheet.Names[$Address].Address
elseif ($Address -is [String] -and $Worksheet -and $Worksheet.Names[$Address] ) { #Address is the name of a named range.
$Address = $Worksheet.Names[$Address].Address
}
if (($Address -is [OfficeOpenXml.ExcelRow] -and -not $WorkSheet) -or
($Address -is [OfficeOpenXml.ExcelColumn] -and -not $WorkSheet) ){ #EPPLUs Can't get the worksheet object from a row or column object, so bail if that was tried
if (($Address -is [OfficeOpenXml.ExcelRow] -and -not $Worksheet) -or
($Address -is [OfficeOpenXml.ExcelColumn] -and -not $Worksheet) ){ #EPPLUs Can't get the worksheet object from a row or column object, so bail if that was tried
Write-Warning -Message "Add-ConditionalFormatting does not support Row or Column objects as an address; use a worksheet and/or specify 'R:R' or 'C:C' instead. "; return
}
elseif ($Address -is [OfficeOpenXml.ExcelRow]) { #But if we have a column or row object and a worksheet (I don't know *why*) turn them into a string for the range
@@ -74,16 +74,16 @@
}
if ( $Address -is [string] -and $Address -match "!") {$Address = $Address -replace '^.*!',''}
#By this point we should have a worksheet object whose ConditionalFormatting collection we will add to. If not, bail.
if (-not $worksheet -or $WorkSheet -isnot [OfficeOpenXml.ExcelWorksheet]) {write-warning "You need to provide a worksheet object." ; return}
if (-not $worksheet -or $Worksheet -isnot [OfficeOpenXml.ExcelWorksheet]) {write-warning "You need to provide a worksheet object." ; return}
#region create a rule of the right type
if ($RuleType -match 'IconSet$') {Write-warning -Message "You cannot configure a Icon-Set rule in this way; please use -$RuleType <SetName>." ; return}
if ($PSBoundParameters.ContainsKey("DataBarColor" ) ) {if ($DataBarColor -is [string]) {$DataBarColor = [System.Drawing.Color]::$DataBarColor }
$rule = $WorkSheet.ConditionalFormatting.AddDatabar( $Address , $DataBarColor )
$rule = $Worksheet.ConditionalFormatting.AddDatabar( $Address , $DataBarColor )
}
elseif ($PSBoundParameters.ContainsKey("ThreeIconsSet" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddThreeIconSet($Address , $ThreeIconsSet)}
elseif ($PSBoundParameters.ContainsKey("FourIconsSet" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddFourIconSet( $Address , $FourIconsSet )}
elseif ($PSBoundParameters.ContainsKey("FiveIconsSet" ) ) {$rule = $WorkSheet.ConditionalFormatting.AddFiveIconSet( $Address , $FiveIconsSet )}
else {$rule = ($WorkSheet.ConditionalFormatting)."Add$RuleType"($Address ) }
elseif ($PSBoundParameters.ContainsKey("ThreeIconsSet" ) ) {$rule = $Worksheet.ConditionalFormatting.AddThreeIconSet($Address , $ThreeIconsSet)}
elseif ($PSBoundParameters.ContainsKey("FourIconsSet" ) ) {$rule = $Worksheet.ConditionalFormatting.AddFourIconSet( $Address , $FourIconsSet )}
elseif ($PSBoundParameters.ContainsKey("FiveIconsSet" ) ) {$rule = $Worksheet.ConditionalFormatting.AddFiveIconSet( $Address , $FiveIconsSet )}
else {$rule = ($Worksheet.ConditionalFormatting)."Add$RuleType"($Address ) }
if ($Reverse) {
if ($rule.type -match 'IconSet$' ) {$rule.reverse = $true}
elseif ($rule.type -match 'ColorScale$') {$temp =$rule.LowValue.Color ; $rule.LowValue.Color = $rule.HighValue.Color; $rule.HighValue.Color = $temp}

View File

@@ -49,7 +49,7 @@ function Add-ExcelChart {
)
try {
if ($PivotTable) {
$Worksheet = $PivotTable.WorkSheet
$Worksheet = $PivotTable.Worksheet
$chart = $Worksheet.Drawings.AddChart(("Chart" + $PivotTable.Name ), $ChartType, $PivotTable)
}
else {
@@ -138,5 +138,5 @@ function Add-ExcelChart {
if ($PassThru) { return $chart }
}
catch { Write-Warning -Message "Failed adding Chart to worksheet '$($WorkSheet).name': $_" }
catch { Write-Warning -Message "Failed adding Chart to worksheet '$($Worksheet).name': $_" }
}

View File

@@ -4,7 +4,7 @@
[Parameter(ValueFromPipeline = $true,Position=0)]
[Alias("Address")]
$Range ,
[OfficeOpenXml.ExcelWorksheet]$WorkSheet ,
[OfficeOpenXml.ExcelWorksheet]$Worksheet ,
[ValidateSet('Any','Custom','DateTime','Decimal','Integer','List','TextLength','Time')]
$ValidationType,
[OfficeOpenXml.DataValidation.ExcelDataValidationOperator]$Operator = [OfficeOpenXml.DataValidation.ExcelDataValidationOperator]::equal ,
@@ -28,13 +28,13 @@
}
else {
#We should accept, a worksheet and a name of a range or a cell address; a table; the address of a table; a named range; a row, a column or .Cells[ ]
if (-not $WorkSheet -and $Range.worksheet) {$WorkSheet = $Range.worksheet}
if (-not $Worksheet -and $Range.worksheet) {$Worksheet = $Range.worksheet}
if ($Range.Address) {$Range = $Range.Address}
if ($Range -isnot [string] -or -not $WorkSheet) {Write-Warning -Message "You need to provide a worksheet and range of cells." ;return}
if ($Range -isnot [string] -or -not $Worksheet) {Write-Warning -Message "You need to provide a worksheet and range of cells." ;return}
#else we assume Range is a range.
$validation = $WorkSheet.DataValidations."Add$ValidationType`Validation"($Range)
$validation = $Worksheet.DataValidations."Add$ValidationType`Validation"($Range)
if ($validation.AllowsOperator) {$validation.Operator = $Operator}
if ($PSBoundParameters.ContainsKey('value')) {
$validation.Formula.Value = $Value

View File

@@ -64,7 +64,7 @@
else {
try {
if (-not $ExcelPackage) {Write-Warning -message "This combination of Parameters needs to include the ExcelPackage." ; return }
[OfficeOpenXml.ExcelWorksheet]$wsPivot = Add-WorkSheet -ExcelPackage $ExcelPackage -WorksheetName $pivotTableName -Activate:$Activate
[OfficeOpenXml.ExcelWorksheet]$wsPivot = Add-Worksheet -ExcelPackage $ExcelPackage -WorksheetName $pivotTableName -Activate:$Activate
if ($wsPivot.Name -ne $PivotTableName) {Write-Warning -Message "The Worksheet name for the PivotTable does not match the table name '$PivotTableName'; probably because excess or illegal characters were removed." }
if ($PivotFilter) {$Address = $wsPivot.Cells["A3"]} else { $Address = $wsPivot.Cells["A1"]}
}

View File

@@ -1,4 +1,4 @@
Function Compare-WorkSheet {
Function Compare-Worksheet {
[cmdletbinding(DefaultParameterSetName)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingWriteHost', '', Justification="Write host used for sub-warning level message to operator which does not form output")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")]
@@ -49,7 +49,7 @@
Catch {Write-Warning -Message "Could not read the worksheet from $Referencefile and/or $Differencefile." ; return }
#Get Column headings and create a hash table of Name to column letter.
$headings = $Sheet1[-1].psobject.Properties.name # This preserves the sequence - using get-member would sort them alphabetically!
$headings = $Sheet1[-1].psobject.Properties.name # This preserves the sequence - using Get-member would sort them alphabetically!
$headings | ForEach-Object -Begin {$columns = @{} ; $i= 1 } -Process {$Columns[$_] = [OfficeOpenXml.ExcelAddress]::GetAddress(1,($i ++)) -replace "\d","" }
#Make a list of property headings using the Property (default "*") and ExcludeProperty parameters
@@ -88,13 +88,13 @@
$ws = $xl.Workbook.Worksheets[$_]
if ($headerName) {$range = "A" + $startrow + ":" + $ws.dimension.end.address}
else {$range = "A" + ($startrow + 1) + ":" + $ws.dimension.end.address}
Set-ExcelRange -WorkSheet $ws -BackgroundColor $AllDataBackgroundColor -Range $Range
Set-ExcelRange -Worksheet $ws -BackgroundColor $AllDataBackgroundColor -Range $Range
}
}
foreach ($row in $file.group) {
$ws = $xl.Workbook.Worksheets[$row._Sheet]
$range = $ws.Dimension -replace "\d+",$row._row
Set-ExcelRange -WorkSheet $ws -Range $range -BackgroundColor $BackgroundColor
Set-ExcelRange -Worksheet $ws -Range $range -BackgroundColor $BackgroundColor
}
if ($PSBoundParameters.ContainsKey("TabColor")) {
if ($TabColor -is [string]) {$TabColor = [System.Drawing.Color]::$TabColor }
@@ -123,8 +123,8 @@
$ws2 = $xl1.Workbook.Worksheets[$u.Group[1]._sheet]
}
if($u.Group[0].$p -ne $u.Group[1].$p ) {
Set-ExcelRange -WorkSheet $ws1 -Range ($Columns[$p] + $u.Group[0]._Row) -FontColor $FontColor
Set-ExcelRange -WorkSheet $ws2 -Range ($Columns[$p] + $u.Group[1]._Row) -FontColor $FontColor
Set-ExcelRange -Worksheet $ws1 -Range ($Columns[$p] + $u.Group[0]._Row) -FontColor $FontColor
Set-ExcelRange -Worksheet $ws2 -Range ($Columns[$p] + $u.Group[1]._Row) -FontColor $FontColor
}
}
}

View File

@@ -43,11 +43,11 @@ $myData = Get-Process | Select-Object -Property Name,WS,CPU,Description,c
$excelPackage = $myData | Export-Excel -KillExcel -Path $Path -WorkSheetname $workSheetname -ClearSheet -AutoSize -AutoFilter -BoldTopRow -FreezeTopRow -PassThru
$workSheet = $excelPackage.Workbook.Worksheets[$workSheetname]
$range = $workSheet.Dimension.Address
Set-ExcelRange -WorkSheet $workSheet -Range "b:b" -NumberFormat "#,###" -AutoFit
Set-ExcelRange -WorkSheet $workSheet -Range "C:C" -NumberFormat "#,##0.00" -AutoFit
Set-ExcelRange -WorkSheet $workSheet -Range "F:F" -NumberFormat "dd MMMM HH:mm:ss" -AutoFit
Add-ConditionalFormatting -WorkSheet $workSheet -Range "c2:c1000" -DataBarColor Blue
Add-ConditionalFormatting -WorkSheet $workSheet -Range "b2:B1000" -RuleType GreaterThan -ConditionValue '104857600' -ForeGroundColor "Red" -Bold
Set-ExcelRange -Worksheet $workSheet -Range "b:b" -NumberFormat "#,###" -AutoFit
Set-ExcelRange -Worksheet $workSheet -Range "C:C" -NumberFormat "#,##0.00" -AutoFit
Set-ExcelRange -Worksheet $workSheet -Range "F:F" -NumberFormat "dd MMMM HH:mm:ss" -AutoFit
Add-ConditionalFormatting -Worksheet $workSheet -Range "c2:c1000" -DataBarColor Blue
Add-ConditionalFormatting -Worksheet $workSheet -Range "b2:B1000" -RuleType GreaterThan -ConditionValue '104857600' -ForeGroundColor "Red" -Bold
Export-Excel -ExcelPackage $excelPackage -WorkSheetname $workSheetname

View File

@@ -1,4 +1,4 @@
function Copy-ExcelWorkSheet {
function Copy-ExcelWorksheet {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true,ValueFromPipeline=$true)]
@@ -39,7 +39,7 @@
return
}
else {
$null = Add-WorkSheet -ExcelPackage $excel -WorkSheetname $DestinationWorksheet -CopySource ($excel.Workbook.Worksheets[$SourceWorkSheet])
$null = Add-Worksheet -ExcelPackage $excel -WorkSheetname $DestinationWorksheet -CopySource ($excel.Workbook.Worksheets[$SourceWorkSheet])
Close-ExcelPackage -ExcelPackage $excel -Show:$Show
return
}
@@ -76,7 +76,7 @@
$DestinationWorkbook.Worksheets.Delete($DestinationWorksheet)
}
Write-Verbose "Copying '$($sourcews.name)' from $($SourceObject) to '$($DestinationWorksheet)' in $($PSBoundParameters['DestinationWorkbook'])"
$null = Add-WorkSheet -ExcelWorkbook $DestinationWorkbook -WorkSheetname $DestinationWorksheet -CopySource $sourceWs
$null = Add-Worksheet -ExcelWorkbook $DestinationWorkbook -WorkSheetname $DestinationWorksheet -CopySource $sourceWs
#Leave the destination open but close the source - if we're copying more than one sheet we'll re-open it and live with the inefficiency
if ($stream) {$stream.Close() }
if ($package1) {Close-ExcelPackage -ExcelPackage $package1 -NoSave }

View File

@@ -124,7 +124,7 @@
try {
$params = @{WorksheetName=$WorksheetName}
foreach ($p in @("ClearSheet", "MoveToStart", "MoveToEnd", "MoveBefore", "MoveAfter", "Activate")) {if ($PSBoundParameters[$p]) {$params[$p] = $PSBoundParameters[$p]}}
$ws = $pkg | Add-WorkSheet @params
$ws = $pkg | Add-Worksheet @params
if ($ws.Name -ne $WorksheetName) {
Write-Warning -Message "The Worksheet name has been changed from $WorksheetName to $($ws.Name), this may cause errors later."
$WorksheetName = $ws.Name
@@ -609,27 +609,27 @@
ForeGroundColor = $c.ConditionalTextColor}
if ($c.Range) {$cfParams.Range = $c.Range}
else {$cfParams.Range = $ws.Dimension.Address }
Add-ConditionalFormatting -WorkSheet $ws @cfParams
Add-ConditionalFormatting -Worksheet $ws @cfParams
Write-Verbose -Message "Added conditional formatting to range $($c.range)"
}
elseif ($c.formatter) {
switch ($c.formatter) {
"ThreeIconSet" {Add-ConditionalFormatting -WorkSheet $ws -ThreeIconsSet $c.IconType -range $c.range -reverse:$c.reverse }
"FourIconSet" {Add-ConditionalFormatting -WorkSheet $ws -FourIconsSet $c.IconType -range $c.range -reverse:$c.reverse }
"FiveIconSet" {Add-ConditionalFormatting -WorkSheet $ws -FiveIconsSet $c.IconType -range $c.range -reverse:$c.reverse }
"ThreeIconSet" {Add-ConditionalFormatting -Worksheet $ws -ThreeIconsSet $c.IconType -range $c.range -reverse:$c.reverse }
"FourIconSet" {Add-ConditionalFormatting -Worksheet $ws -FourIconsSet $c.IconType -range $c.range -reverse:$c.reverse }
"FiveIconSet" {Add-ConditionalFormatting -Worksheet $ws -FiveIconsSet $c.IconType -range $c.range -reverse:$c.reverse }
}
Write-Verbose -Message "Added conditional formatting to range $($c.range)"
}
elseif ($c -is [hashtable] -or $c -is[System.Collections.Specialized.OrderedDictionary]) {
if (-not $c.Range -or $c.Address) {$c.Address = $ws.Dimension.Address }
Add-ConditionalFormatting -WorkSheet $ws @c
Add-ConditionalFormatting -Worksheet $ws @c
}
}
catch {throw "Error applying conditional formatting to worksheet $_"}
}
foreach ($s in $Style) {
if (-not $s.Range) {$s["Range"] = $ws.Dimension.Address }
Set-ExcelRange -WorkSheet $ws @s
Set-ExcelRange -Worksheet $ws @s
}
if ($CellStyleSB) {
try {

View File

@@ -1,14 +1,4 @@
function Import-USPS {
param(
$TrackingNumber,
[Switch]$UseDefaultCredentials
)
Import-Html "https://tools.usps.com/go/TrackConfirmAction?qtc_tLabels1=$($TrackingNumber)" 0 -UseDefaultCredentials: $UseDefaultCredentials
}
function Import-UPS {
function Import-UPS {
param(
$TrackingNumber,
[Switch]$UseDefaultCredentials

View File

@@ -1,4 +1,5 @@
function Import-USPS {
param(
$TrackingNumber,
[Switch]$UseDefaultCredentials

View File

@@ -55,7 +55,7 @@
)
#region get target worksheet, select it and move it to the end.
if ($Path -and -not $ExcelPackage) {$ExcelPackage = Open-ExcelPackage -path $Path }
$destinationSheet = Add-WorkSheet -ExcelPackage $ExcelPackage -WorkSheetname $WorkSheetName -ClearSheet:$Clearsheet
$destinationSheet = Add-Worksheet -ExcelPackage $ExcelPackage -WorkSheetname $WorkSheetName -ClearSheet:$Clearsheet
foreach ($w in $ExcelPackage.Workbook.Worksheets) {$w.view.TabSelected = $false}
$destinationSheet.View.TabSelected = $true
$ExcelPackage.Workbook.Worksheets.MoveToEnd($WorkSheetName)
@@ -117,7 +117,7 @@
if ($HideSource) {$sourceWorksheet.Hidden = [OfficeOpenXml.eWorkSheetHidden]::Hidden}
}
#We accept a bunch of parameters work to pass on to Export-excel ( Autosize, Autofilter, boldtopRow Freeze ); if we have any of those call export-excel otherwise close the package here.
#We accept a bunch of parameters work to pass on to Export-excel ( Autosize, Autofilter, boldtopRow Freeze ); if we have any of those call Export-excel otherwise close the package here.
$params = @{} + $PSBoundParameters
'Path', 'Clearsheet', 'NoHeader', 'FromLabel', 'LabelBlocks', 'HideSource',
'Title', 'TitleFillPattern', 'TitleBackgroundColor', 'TitleBold', 'TitleSize' | ForEach-Object {$null = $params.Remove($_)}

View File

@@ -115,7 +115,7 @@
#Make a list of properties/headings using the Property (default "*") and ExcludeProperty parameters
$propList = @()
$DifferenceObject = $DifferenceObject | Update-FirstObjectProperties
$headings = $DifferenceObject[0].psobject.Properties.Name # This preserves the sequence - using get-member would sort them alphabetically! There may be extra properties in
$headings = $DifferenceObject[0].psobject.Properties.Name # This preserves the sequence - using Get-member would sort them alphabetically! There may be extra properties in
if ($NoHeader -and "Name" -eq $Key) {$Key = "p1"}
if ($headings -notcontains $Key -and
('*' -ne $Key)) {Write-Warning -Message "You need to specify one of the headings in the sheet '$Worksheet1' as a key." ; return }

View File

@@ -1,4 +1,4 @@
Function Remove-WorkSheet {
Function Remove-Worksheet {
[cmdletbinding(SupportsShouldProcess=$true)]
param(
# [Parameter(ValueFromPipelineByPropertyName)]
@@ -11,7 +11,7 @@
Process {
if (!$FullName) {
throw "Remove-WorkSheet requires the and Excel file"
throw "Remove-Worksheet requires the and Excel file"
}
$pkg = Open-ExcelPackage -Path $FullName

View File

@@ -3,14 +3,14 @@ param()
function Set-CellStyle {
param(
$WorkSheet,
$Worksheet,
$Row,
$LastColumn,
[OfficeOpenXml.Style.ExcelFillStyle]$Pattern,
$Color
)
if ($Color -is [string]) {$Color = [System.Drawing.Color]::$Color }
$t=$WorkSheet.Cells["A$($Row):$($LastColumn)$($Row)"]
$t=$Worksheet.Cells["A$($Row):$($LastColumn)$($Row)"]
$t.Style.Fill.PatternType=$Pattern
$t.Style.Fill.BackgroundColor.SetColor($Color)
}

View File

@@ -116,7 +116,7 @@
}
if ($params.Count) {
$theRange = "$columnName$StartRow`:$columnName$endRow"
Set-ExcelRange -WorkSheet $Worksheet -Range $theRange @params
Set-ExcelRange -Worksheet $Worksheet -Range $theRange @params
}
#endregion
if ($PSBoundParameters.ContainsKey('Hide')) {$workSheet.Column($Column).Hidden = [bool]$Hide}

View File

@@ -6,7 +6,7 @@
[Parameter(ValueFromPipeline = $true,Position=0)]
[Alias("Address")]
$Range ,
[OfficeOpenXml.ExcelWorksheet]$WorkSheet ,
[OfficeOpenXml.ExcelWorksheet]$Worksheet ,
[Alias("NFormat")]
$NumberFormat,
[OfficeOpenXml.Style.ExcelBorderStyle]$BorderAround,
@@ -54,8 +54,8 @@
else {
#We should accept, a worksheet and a name of a range or a cell address; a table; the address of a table; a named range; a row, a column or .Cells[ ]
if ($Range -is [OfficeOpenXml.Table.ExcelTable]) {$Range = $Range.Address}
elseif ($WorkSheet -and ($Range -is [string] -or $Range -is [OfficeOpenXml.ExcelAddress])) {
$Range = $WorkSheet.Cells[$Range]
elseif ($Worksheet -and ($Range -is [string] -or $Range -is [OfficeOpenXml.ExcelAddress])) {
$Range = $Worksheet.Cells[$Range]
}
elseif ($Range -is [string]) {Write-Warning -Message "The range pararameter you have specified also needs a worksheet parameter." ;return}
#else we assume $Range is a range.
@@ -159,7 +159,7 @@
if ($Range -is [OfficeOpenXml.ExcelRow] ) {$Range.Height = $Height }
elseif ($Range -is [OfficeOpenXml.ExcelRange] ) {
($Range.Start.Row)..($Range.Start.Row + $Range.Rows) |
ForEach-Object {$Range.WorkSheet.Row($_).Height = $Height }
ForEach-Object {$Range.Worksheet.Row($_).Height = $Height }
}
else {Write-Warning -Message ("Can set the height of a row or a range but not a {0} object" -f ($Range.GetType().name)) }
}

View File

@@ -113,7 +113,7 @@
}
if ($params.Count) {
$theRange = New-Object -TypeName OfficeOpenXml.ExcelAddress @($Row, $StartColumn, $Row, $endColumn)
Set-ExcelRange -WorkSheet $Worksheet -Range $theRange @params
Set-ExcelRange -Worksheet $Worksheet -Range $theRange @params
}
#endregion
if ($PSBoundParameters.ContainsKey('Hide')) {$workSheet.Row($Row).Hidden = [bool]$Hide}

View File

@@ -1,9 +1,9 @@
Function Set-WorkSheetProtection {
Function Set-WorksheetProtection {
[Cmdletbinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '',Justification='Does not change system state')]
param (
[Parameter(Mandatory=$true)]
[OfficeOpenXml.ExcelWorksheet]$WorkSheet ,
[OfficeOpenXml.ExcelWorksheet]$Worksheet ,
[switch]$IsProtected,
[switch]$AllowAll,
[switch]$BlockSelectLockedCells,
@@ -44,12 +44,12 @@
Else {Write-Warning -Message "You haven't said if you want to turn protection off, or on." }
if ($LockAddress) {
Set-ExcelRange -Range $WorkSheet.cells[$LockAddress] -Locked
Set-ExcelRange -Range $Worksheet.cells[$LockAddress] -Locked
}
elseif ($IsProtected) {
Set-ExcelRange -Range $WorkSheet.Cells -Locked
Set-ExcelRange -Range $Worksheet.Cells -Locked
}
if ($UnlockAddress) {
Set-ExcelRange -Range $WorkSheet.cells[$UnlockAddress] -Locked:$false
Set-ExcelRange -Range $Worksheet.cells[$UnlockAddress] -Locked:$false
}
}

View File

@@ -68,17 +68,17 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5
'Add-ExcelName',
'Add-ExcelTable',
'Add-PivotTable',
'Add-WorkSheet',
'Add-Worksheet',
'BarChart',
'Close-ExcelPackage',
'ColumnChart',
'Compare-WorkSheet',
'Compare-Worksheet',
'Convert-ExcelRangeToImage',
'ConvertFrom-ExcelData',
'ConvertFrom-ExcelSheet',
'ConvertFrom-ExcelToSQLInsert',
'ConvertTo-ExcelXlsx',
'Copy-ExcelWorkSheet',
'Copy-ExcelWorksheet',
'DoChart',
'Expand-NumberFormat',
'Export-Excel',
@@ -110,14 +110,14 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5
'Open-ExcelPackage',
'PieChart',
'Pivot',
'Remove-WorkSheet'
'Remove-Worksheet'
'Select-Worksheet',
'Send-SQLDataToExcel',
'Set-CellStyle',
'Set-ExcelColumn',
'Set-ExcelRange',
'Set-ExcelRow',
'Set-WorkSheetProtection',
'Set-WorksheetProtection',
'Test-Boolean',
'Test-Date',
'Test-Integer',

View File

@@ -32,7 +32,7 @@ else {
if (($IsLinux -or $IsMacOS) -or $env:NoAutoSize) {
$ExcelPackage = [OfficeOpenXml.ExcelPackage]::new()
$Cells = ($ExcelPackage | Add-WorkSheet).Cells['A1']
$Cells = ($ExcelPackage | Add-Worksheet).Cells['A1']
$Cells.Value = 'Test'
try {
$Cells.AutoFitColumns()

View File

@@ -29,12 +29,12 @@ $IncludeFiles = @(
'AddDataValidation.ps1',
'Charting.ps1',
'ColorCompletion.ps1',
'Compare-WorkSheet.ps1',
'Compare-Worksheet.ps1',
'ConvertExcelToImageFile.ps1',
'ConvertFromExcelData.ps1',
'ConvertFromExcelToSQLInsert.ps1',
'ConvertToExcelXlsx.ps1',
'Copy-ExcelWorkSheet.ps1',
'Copy-ExcelWorksheet.ps1',
'Export-Excel.ps1',
'Export-ExcelSheet.ps1',
'Export-StocksToExcel.ps1',
@@ -62,7 +62,7 @@ $IncludeFiles = @(
'Set-CellStyle.ps1',
'Set-Column.ps1',
'Set-Row.ps1',
'Set-WorkSheetProtection.ps1',
'Set-WorksheetProtection.ps1',
'SetFormat.ps1',
'TrackingUtils.ps1',
'Update-FirstObjectProperties.ps1'

View File

@@ -1,4 +1,4 @@
if (-not (get-command Import-Excel -ErrorAction SilentlyContinue)) {
if (-not (Get-command Import-Excel -ErrorAction SilentlyContinue)) {
Import-Module $PSScriptRoot\..\ImportExcel.psd1
}
Describe "Test adding trendlines to charts" {

View File

@@ -1,7 +1,7 @@
#Requires -Modules Pester
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments','',Justification='False Positives')]
param()
if (-not (get-command Import-Excel -ErrorAction SilentlyContinue)) {
if (-not (Get-command Import-Excel -ErrorAction SilentlyContinue)) {
Import-Module $PSScriptRoot\..\ImportExcel.psd1
}
Describe "Compare Worksheet" {
@@ -27,7 +27,7 @@ Describe "Compare Worksheet" {
$s.RemoveAt(5)
$s | Export-Excel -Path TestDrive:\server2.xlsx
#Assume default worksheet name, (sheet1) and column header for key ("name")
$comp = compare-WorkSheet "TestDrive:\server1.xlsx" "TestDrive:\server2.xlsx" | Sort-Object -Property _row, _file
$comp = Compare-Worksheet "TestDrive:\server1.xlsx" "TestDrive:\server2.xlsx" | Sort-Object -Property _row, _file
}
Context "Simple comparison output" {
it "Found the right number of differences " {
@@ -59,7 +59,7 @@ Describe "Compare Worksheet" {
Context "Setting the background to highlight different rows" {
BeforeAll {
$null = Compare-WorkSheet "TestDrive:\server1.xlsx" "TestDrive:\server2.xlsx" -BackgroundColor ([System.Drawing.Color]::LightGreen)
$null = Compare-Worksheet "TestDrive:\server1.xlsx" "TestDrive:\server2.xlsx" -BackgroundColor ([System.Drawing.Color]::LightGreen)
$xl1 = Open-ExcelPackage -Path "TestDrive:\server1.xlsx"
$xl2 = Open-ExcelPackage -Path "TestDrive:\server2.xlsx"
$s1Sheet = $xl1.Workbook.Worksheets[1]
@@ -85,7 +85,7 @@ Describe "Compare Worksheet" {
Context "Setting the forgound to highlight changed properties" {
BeforeAll {
$null = compare-WorkSheet "TestDrive:\server1.xlsx" "TestDrive:\server2.xlsx" -AllDataBackgroundColor([System.Drawing.Color]::white) -BackgroundColor ([System.Drawing.Color]::LightGreen) -FontColor ([System.Drawing.Color]::DarkRed)
$null = Compare-Worksheet "TestDrive:\server1.xlsx" "TestDrive:\server2.xlsx" -AllDataBackgroundColor([System.Drawing.Color]::white) -BackgroundColor ([System.Drawing.Color]::LightGreen) -FontColor ([System.Drawing.Color]::DarkRed)
$xl1 = Open-ExcelPackage -Path "TestDrive:\server1.xlsx"
$xl2 = Open-ExcelPackage -Path "TestDrive:\server2.xlsx"
$s1Sheet = $xl1.Workbook.Worksheets[1]
@@ -114,7 +114,7 @@ Describe "Compare Worksheet" {
Context "More complex comparison: output check and different worksheet names " {
BeforeAll {
[System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property RequiredServices, CanPauseAndContinue, CanShutdown, CanStop,
[System.Collections.ArrayList]$s = Get-service | Select-Object -first 25 -Property RequiredServices, CanPauseAndContinue, CanShutdown, CanStop,
DisplayName, DependentServices, MachineName, ServiceName, ServicesDependedOn, ServiceHandle, Status, ServiceType, StartType -ExcludeProperty Name
$s | Export-Excel -Path TestDrive:\server1.xlsx -WorkSheetname server1
#$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
@@ -130,7 +130,7 @@ Describe "Compare Worksheet" {
$s | Select-Object -Property ServiceName, DisplayName, StartType, ServiceType | Export-Excel -Path TestDrive:\server2.xlsx -WorkSheetname server2
#Assume default worksheet name, (sheet1) and column header for key ("name")
$comp = compare-WorkSheet "TestDrive:\server1.xlsx" "TestDrive:\server2.xlsx" -WorkSheetName server1,server2 -Key ServiceName -Property DisplayName,StartType -AllDataBackgroundColor ([System.Drawing.Color]::AliceBlue) -BackgroundColor ([System.Drawing.Color]::White) -FontColor ([System.Drawing.Color]::Red) | Sort-Object _row,_file
$comp = Compare-Worksheet "TestDrive:\server1.xlsx" "TestDrive:\server2.xlsx" -WorkSheetName server1,server2 -Key ServiceName -Property DisplayName,StartType -AllDataBackgroundColor ([System.Drawing.Color]::AliceBlue) -BackgroundColor ([System.Drawing.Color]::White) -FontColor ([System.Drawing.Color]::Red) | Sort-Object _row,_file
$xl1 = Open-ExcelPackage -Path "TestDrive:\server1.xlsx"
$xl2 = Open-ExcelPackage -Path "TestDrive:\server2.xlsx"
$s1Sheet = $xl1.Workbook.Worksheets["server1"]
@@ -188,7 +188,7 @@ Describe "Compare Worksheet" {
Describe "Merge Worksheet" {
BeforeAll {
Remove-Item -Path "TestDrive:\server*.xlsx" , "TestDrive:\combined*.xlsx" -ErrorAction SilentlyContinue
[System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property *
[System.Collections.ArrayList]$s = Get-service | Select-Object -first 25 -Property *
$s | Export-Excel -Path TestDrive:\server1.xlsx
@@ -255,7 +255,7 @@ Describe "Merge Multiple sheets" {
Context "Merge 3 sheets with 3 properties" {
BeforeAll {
Remove-Item -Path "TestDrive:\server*.xlsx" , "TestDrive:\combined*.xlsx" -ErrorAction SilentlyContinue
[System.Collections.ArrayList]$s = get-service | Select-Object -first 25 -Property Name,DisplayName,StartType
[System.Collections.ArrayList]$s = Get-service | Select-Object -first 25 -Property Name,DisplayName,StartType
$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

View File

@@ -1,4 +1,4 @@
if (-not (get-command Import-Excel -ErrorAction SilentlyContinue)) {
if (-not (Get-command Import-Excel -ErrorAction SilentlyContinue)) {
Import-Module $PSScriptRoot\..\ImportExcel.psd1
}
$xlFile = "TestDrive:\testSQL.xlsx"

View File

@@ -36,7 +36,7 @@ Describe "Copy-Worksheet" {
} | Export-Excel -NoNumberConversion IPAddress, StrLeadZero, StrAltPhone2 -WorkSheetname MixedTypes -Path $path2
Context "Simplest copy" {
BeforeAll {
Copy-ExcelWorkSheet -SourceWorkbook $path1 -DestinationWorkbook $path2
Copy-ExcelWorksheet -SourceWorkbook $path1 -DestinationWorkbook $path2
$excel = Open-ExcelPackage -Path $path2
$ws = $excel.Workbook.Worksheets["Processes"]
}
@@ -48,7 +48,7 @@ Describe "Copy-Worksheet" {
}
Context "Mixed types using a package object" {
BeforeAll {
Copy-ExcelWorkSheet -SourceWorkbook $excel -DestinationWorkbook $excel -DestinationWorkSheet "CopyOfMixedTypes"
Copy-ExcelWorksheet -SourceWorkbook $excel -DestinationWorkbook $excel -DestinationWorkSheet "CopyOfMixedTypes"
Close-ExcelPackage -ExcelPackage $excel
$excel = Open-ExcelPackage -Path $path2
$ws = $Excel.Workbook.Worksheets[3]
@@ -108,10 +108,10 @@ Describe "Copy-Worksheet" {
$targetSheets = "1.1.2019", "1.4.2019"
$targetSheets | ForEach-Object {
Copy-ExcelWorkSheet -SourceWorkbook $xlfile -DestinationWorkbook $xlfileArchive -SourceWorkSheet $_ -DestinationWorkSheet $_
Copy-ExcelWorksheet -SourceWorkbook $xlfile -DestinationWorkbook $xlfileArchive -SourceWorkSheet $_ -DestinationWorkSheet $_
}
$targetSheets | ForEach-Object { Remove-WorkSheet -FullName $xlfile -WorksheetName $_ }
$targetSheets | ForEach-Object { Remove-Worksheet -FullName $xlfile -WorksheetName $_ }
(Get-ExcelSheetInfo -Path $xlfile ).Count | Should Be 3
}
@@ -131,7 +131,7 @@ Describe "Copy-Worksheet" {
"Hello World" | Export-Excel $xlfile -WorksheetName $_
}
$e = Open-ExcelPackage $xlfile
$e.Workbook.Worksheets | Copy-ExcelWorkSheet -DestinationWorkbook $xlfileArchive
$e.Workbook.Worksheets | Copy-ExcelWorksheet -DestinationWorkbook $xlfileArchive
Close-ExcelPackage -NoSave $e
}
it "Should copy sheets piped into the command " {

View File

@@ -2,7 +2,7 @@
[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)) {
if (-not (Get-command Import-Excel -ErrorAction SilentlyContinue)) {
Import-Module $PSScriptRoot\..\ImportExcel.psd1
}
if ($null -eq $IsWindows) {$IsWindows = [environment]::OSVersion.Platform -like "win*"}
@@ -397,7 +397,7 @@ Describe ExportExcel {
}
}
#Test adding mutliple conditional blocks and using the minimal syntax for new-ConditionalText
#Test adding mutliple conditional blocks and using the minimal syntax for New-ConditionalText
$path = "TestDrive:\test.xlsx"
Remove-item -Path $path -ErrorAction SilentlyContinue
@@ -523,15 +523,15 @@ Describe ExportExcel {
Context " # Add-Worksheet inserted sheets, moved them correctly, and copied a sheet" {
$path = "TestDrive:\test.xlsx"
#Test the -CopySource and -Movexxxx parameters for Add-WorkSheet
#Test the -CopySource and -Movexxxx parameters for Add-Worksheet
$Excel = Open-ExcelPackage $path
#At this point Sheets Should be in the order Sheet1, Processes, ProcessesPivotTable
$null = Add-WorkSheet -ExcelPackage $Excel -WorkSheetname "Processes" -MoveToEnd # order now Sheet1, ProcessesPivotTable, Processes
$null = Add-WorkSheet -ExcelPackage $Excel -WorkSheetname "NewSheet" -MoveAfter "*" -CopySource ($excel.Workbook.Worksheets["Sheet1"]) # Now its NewSheet, Sheet1, ProcessesPivotTable, Processes
$null = Add-WorkSheet -ExcelPackage $Excel -WorkSheetname "Sheet1" -MoveAfter "Processes" # Now its NewSheet, ProcessesPivotTable, Processes, Sheet1
$null = Add-WorkSheet -ExcelPackage $Excel -WorkSheetname "Another" -MoveToStart # Now its Another, NewSheet, ProcessesPivotTable, Processes, Sheet1
$null = Add-WorkSheet -ExcelPackage $Excel -WorkSheetname "NearDone" -MoveBefore 5 # Now its Another, NewSheet, ProcessesPivotTable, Processes, NearDone ,Sheet1
$null = Add-WorkSheet -ExcelPackage $Excel -WorkSheetname "OneLast" -MoveBefore "ProcessesPivotTable" # Now its Another, NewSheet, Onelast, ProcessesPivotTable, Processes,NearDone ,Sheet1
$null = Add-Worksheet -ExcelPackage $Excel -WorkSheetname "Processes" -MoveToEnd # order now Sheet1, ProcessesPivotTable, Processes
$null = Add-Worksheet -ExcelPackage $Excel -WorkSheetname "NewSheet" -MoveAfter "*" -CopySource ($excel.Workbook.Worksheets["Sheet1"]) # Now its NewSheet, Sheet1, ProcessesPivotTable, Processes
$null = Add-Worksheet -ExcelPackage $Excel -WorkSheetname "Sheet1" -MoveAfter "Processes" # Now its NewSheet, ProcessesPivotTable, Processes, Sheet1
$null = Add-Worksheet -ExcelPackage $Excel -WorkSheetname "Another" -MoveToStart # Now its Another, NewSheet, ProcessesPivotTable, Processes, Sheet1
$null = Add-Worksheet -ExcelPackage $Excel -WorkSheetname "NearDone" -MoveBefore 5 # Now its Another, NewSheet, ProcessesPivotTable, Processes, NearDone ,Sheet1
$null = Add-Worksheet -ExcelPackage $Excel -WorkSheetname "OneLast" -MoveBefore "ProcessesPivotTable" # Now its Another, NewSheet, Onelast, ProcessesPivotTable, Processes,NearDone ,Sheet1
Close-ExcelPackage $Excel
$Excel = Open-ExcelPackage $path
@@ -735,10 +735,10 @@ Describe ExportExcel {
Set-ExcelRange -Address $sheet.Cells["E1:H1048576"] -HorizontalAlignment Right -NFormat "#,###"
Set-ExcelRange -Address $sheet.Column(4) -HorizontalAlignment Right -NFormat "#,##0.0" -Bold
Set-ExcelRange -Address $sheet.Row(1) -Bold -HorizontalAlignment Center
Add-ConditionalFormatting -WorkSheet $sheet -Range "D2:D1048576" -DataBarColor ([System.Drawing.Color]::Red)
Add-ConditionalFormatting -Worksheet $sheet -Range "D2:D1048576" -DataBarColor ([System.Drawing.Color]::Red)
#test Add-ConditionalFormatting -passthru and using a range (and no worksheet)
$rule = Add-ConditionalFormatting -passthru -Address $sheet.cells["C:C"] -RuleType TopPercent -ConditionValue 20 -Bold -StrikeThru
Add-ConditionalFormatting -WorkSheet $sheet -Range "G2:G1048576" -RuleType GreaterThan -ConditionValue "104857600" -ForeGroundColor ([System.Drawing.Color]::Red) -Bold -Italic -Underline -BackgroundColor ([System.Drawing.Color]::Beige) -BackgroundPattern LightUp -PatternColor ([System.Drawing.Color]::Gray)
Add-ConditionalFormatting -Worksheet $sheet -Range "G2:G1048576" -RuleType GreaterThan -ConditionValue "104857600" -ForeGroundColor ([System.Drawing.Color]::Red) -Bold -Italic -Underline -BackgroundColor ([System.Drawing.Color]::Beige) -BackgroundPattern LightUp -PatternColor ([System.Drawing.Color]::Gray)
#Test Set-ExcelRange with a column
if ($isWindows) { foreach ($c in 5..9) {Set-ExcelRange $sheet.Column($c) -AutoFit } }
Add-PivotTable -PivotTableName "PT_Procs" -ExcelPackage $excel -SourceWorkSheet 1 -PivotRows Company -PivotData @{'Name' = 'Count'} -IncludePivotChart -ChartType ColumnClustered -NoLegend
@@ -810,8 +810,8 @@ Describe ExportExcel {
Remove-Item -Path $path -ErrorAction SilentlyContinue
#Test we haven't missed any parameters on New-ChartDefinition which are on add chart or vice versa.
$ParamChk1 = (get-command Add-ExcelChart ).Parameters.Keys.where({-not (get-command New-ExcelChartDefinition).Parameters.ContainsKey($_) }) | Sort-Object
$ParamChk2 = (get-command New-ExcelChartDefinition).Parameters.Keys.where({-not (get-command Add-ExcelChart ).Parameters.ContainsKey($_) })
$ParamChk1 = (Get-command Add-ExcelChart ).Parameters.Keys.where({-not (Get-command New-ExcelChartDefinition).Parameters.ContainsKey($_) }) | Sort-Object
$ParamChk2 = (Get-command New-ExcelChartDefinition).Parameters.Keys.where({-not (Get-command Add-ExcelChart ).Parameters.ContainsKey($_) })
it "Found the same parameters for Add-ExcelChart and New-ExcelChartDefinintion " {
$ParamChk1.count | Should be 3
$ParamChk1[0] | Should be "PassThru"
@@ -872,7 +872,7 @@ Describe ExportExcel {
-Column 2 -ColumnOffSetPixels 35 -Width 800 -XAxisTitleText "Degrees" -XAxisTitleBold -XAxisTitleSize 12 -XMajorUnit 30 -XMinorUnit 10 -XMinValue 0 -XMaxValue 361 -XAxisNumberformat "000" `
-YMinValue -1.25 -YMaxValue 1.25 -YMajorUnit 0.25 -YAxisNumberformat "0.00" -YAxisTitleText "Sine" -YAxisTitleBold -YAxisTitleSize 12 `
-LegendSize 8 -legendBold -LegendPosition Bottom
Add-ConditionalFormatting -WorkSheet $excel.Workbook.Worksheets["Sinx"] -Range "B2:B362" -RuleType LessThan -ConditionValue "=B1" -ForeGroundColor ([System.Drawing.Color]::Red)
Add-ConditionalFormatting -Worksheet $excel.Workbook.Worksheets["Sinx"] -Range "B2:B362" -RuleType LessThan -ConditionValue "=B1" -ForeGroundColor ([System.Drawing.Color]::Red)
$ws = $Excel.Workbook.Worksheets["Sinx"]
$d = $ws.Drawings[0]
It "Controled the axes and title and legend of the chart " {

View File

@@ -32,7 +32,7 @@ Describe "Creating small named ranges with hyperlinks" {
#create a table which covers all the data. And define a pivot table which uses the same address range.
$table = Add-ExcelTable -PassThru -Range $worksheet.cells[$topRow, 1, $lastDataRow, $columns] -TableName "AllResults" -TableStyle Light4 `
-ShowHeader -ShowFilter -ShowColumnStripes -ShowRowStripes:$false -ShowFirstColumn:$false -ShowLastColumn:$false -ShowTotal:$false #Test Add-ExcelTable outside export-Excel with as many options as possible.
-ShowHeader -ShowFilter -ShowColumnStripes -ShowRowStripes:$false -ShowFirstColumn:$false -ShowLastColumn:$false -ShowTotal:$false #Test Add-ExcelTable outside Export-Excel with as many options as possible.
$pt = New-PivotTableDefinition -PivotTableName Analysis -SourceWorkSheet $worksheet -SourceRange $table.address.address -PivotRows Driver -PivotData @{Points = "SUM"} -PivotTotals None
$cf = Add-ConditionalFormatting -Address $worksheet.cells[$topRow, $columns, $lastDataRow, $columns] -ThreeIconsSet Arrows -Passthru #Test using cells[r1,c1,r2,c2]
@@ -42,15 +42,15 @@ Describe "Creating small named ranges with hyperlinks" {
Add-ConditionalFormatting -Address $worksheet.cells["FinishPosition"] -RuleType Equal -ConditionValue 1 -ForeGroundColor ([System.Drawing.Color]::Purple) -Bold -Priority 1 -StopIfTrue #Test Priority and stopIfTrue and using range name
Add-ConditionalFormatting -Address $worksheet.Cells["GridPosition"] -RuleType ThreeColorScale -Reverse #Test Reverse
$ct = New-ConditionalText -Text "Ferrari"
$ct2 = New-ConditionalText -Range $worksheet.Names["FinishPosition"].Address -ConditionalType LessThanOrEqual -Text 3 -ConditionalText ([System.Drawing.Color]::Red) -Background ([System.Drawing.Color]::White) #Test new-conditionalText in shortest and longest forms.
$ct2 = New-ConditionalText -Range $worksheet.Names["FinishPosition"].Address -ConditionalType LessThanOrEqual -Text 3 -ConditionalText ([System.Drawing.Color]::Red) -Background ([System.Drawing.Color]::White) #Test New-ConditionalText in shortest and longest forms.
#Create links for each group name (race) and Export them so they start at Cell A1; create a pivot table with definition just created, save the file and open in Excel
$excel = $results | ForEach-Object {(New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList "Sheet1!$($_.Name)" , "$($_.name) GP")} | #Test Exporting Hyperlinks with display property.
Export-Excel -ExcelPackage $excel -AutoSize -PivotTableDefinition $pt -Calculate -ConditionalFormat $ct, $ct2 -PassThru #Test conditional text rules in conditional format (orignally icon sets only )
$null = Add-WorkSheet -ExcelPackage $excel -WorksheetName "Points1"
$null = Add-Worksheet -ExcelPackage $excel -WorksheetName "Points1"
Add-PivotTable -PivotTableName "Points1" -Address $excel.Points1.Cells["A1"] -ExcelPackage $excel -SourceWorkSheet sheet1 -SourceRange $excel.Sheet1.Tables[0].Address.Address -PivotRows Driver, Date -PivotData @{Points = "SUM"} -GroupDateRow Date -GroupDatePart Years, Months
$null = Add-WorkSheet -ExcelPackage $excel -WorksheetName "Places1"
$null = Add-Worksheet -ExcelPackage $excel -WorksheetName "Places1"
$newpt = Add-PivotTable -PivotTableName "Places1" -Address $excel.Places1.Cells["A1"] -ExcelPackage $excel -SourceWorkSheet sheet1 -SourceRange $excel.Sheet1.Tables[0].Address.Address -PivotRows Driver, FinishPosition -PivotData @{Date = "Count"} -GroupNumericRow FinishPosition -GroupNumericMin 1 -GroupNumericMax 25 -GroupNumericInterval 3 -PassThru
$newpt.RowFields[0].SubTotalFunctions = [OfficeOpenXml.Table.PivotTable.eSubTotalFunctions]::None
Close-ExcelPackage -ExcelPackage $excel

View File

@@ -1,5 +1,5 @@
#Requires -Modules Pester
if (-not (get-command Import-Excel -ErrorAction SilentlyContinue)) {
if (-not (Get-command Import-Excel -ErrorAction SilentlyContinue)) {
Import-Module $PSScriptRoot\..\ImportExcel.psd1
}

View File

@@ -3,19 +3,19 @@ $xlfile = "TestDrive:\testImportExcel.xlsx"
Describe "Import-Excel on a sheet with no headings" {
BeforeAll {
$xl = "" | export-excel $xlfile -PassThru
$xl = "" | Export-excel $xlfile -PassThru
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-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-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-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-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'
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
}
@@ -158,22 +158,22 @@ Describe "Import-Excel on a sheet with no headings" {
It "Should" {
$xlfile = "TestDrive:\testImportExcelSparse.xlsx"
$xl = "" | export-excel $xlfile -PassThru
$xl = "" | Export-excel $xlfile -PassThru
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-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-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-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-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'
Set-ExcelRange -Worksheet $xl.Sheet1 -Range A3 -Value 'Jean-Claude'
Set-ExcelRange -Worksheet $xl.Sheet1 -Range B3 -Value ''
Set-ExcelRange -Worksheet $xl.Sheet1 -Range C3 -Value 'Vandamme'
Set-ExcelRange -Worksheet $xl.Sheet1 -Range D3 -Value 'Brussels'
Close-ExcelPackage $xl

View File

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

View File

@@ -181,7 +181,7 @@ Describe "Exporting with -Inputobject, table handling, Send-SQL-Data. Checking I
Close-ExcelPackage $excel
Context "Import As Text returns text values" {
$x = import-excel $path -WorksheetName sheet3 -AsText StartTime,hand* | Select-Object -last 1
$x = Import-excel $path -WorksheetName sheet3 -AsText StartTime,hand* | Select-Object -last 1
it "Had fields of type string, not date or int, where specified as ASText " {
$x.Handles.GetType().Name | should be "String"
$x.StartTime.GetType().Name | should be "String"

View File

@@ -25,7 +25,7 @@ Describe "Password Support" {
{Import-Excel $Path } | should throw
}
it "Could read the file when the password was included " {
(import-excel $path -Password $password).count | should be 20
(Import-excel $path -Password $password).count | should be 20
}
}
}

View File

@@ -15,7 +15,7 @@ Apple, New York, 1200,700
$ws = $excel.sheet1
Set-WorkSheetProtection -WorkSheet $ws -IsProtected -BlockEditObject -AllowFormatRows -UnLockAddress "1:1"
Set-WorksheetProtection -Worksheet $ws -IsProtected -BlockEditObject -AllowFormatRows -UnLockAddress "1:1"
Close-ExcelPackage -ExcelPackage $excel
$excel = Open-ExcelPackage -Path $path

View File

@@ -16,11 +16,11 @@ describe "Consistent passing of ranges." {
$warnvar | should not beNullOrEmpty
$excel.Services.ConditionalFormatting.Count | Should be 2
$warnvar = $null
Add-ConditionalFormatting $excel.Services.Column(3) -WorkSheet $excel.Services`
Add-ConditionalFormatting $excel.Services.Column(3) -Worksheet $excel.Services`
-underline -RuleType ContainsText -ConditionValue "Windows" -WarningVariable warnvar -WarningAction SilentlyContinue
$warnvar | should beNullOrEmpty
$excel.Services.ConditionalFormatting.Count | Should be 3
{Add-ConditionalFormatting "Status" -WorkSheet $excel.Services `
{Add-ConditionalFormatting "Status" -Worksheet $excel.Services `
-ForeGroundColor ([System.Drawing.Color]::Green) -RuleType ContainsText -ConditionValue "Running"} | Should not throw
$excel.Services.ConditionalFormatting.Count | Should be 4
}
@@ -33,36 +33,36 @@ describe "Consistent passing of ranges." {
{Add-ConditionalFormatting $excel.Services.Tables["ServiceTable"].Address `
-Bold -RuleType ContainsText -ConditionValue "windows" } | Should not throw
$excel.Services.ConditionalFormatting.Count | Should be 2
{Add-ConditionalFormatting -WorkSheet $excel.Services -Address "a:a" `
{Add-ConditionalFormatting -Worksheet $excel.Services -Address "a:a" `
-RuleType ContainsText -ConditionValue "stopped" -ForeGroundColor ([System.Drawing.Color]::Red) } | Should not throw
$excel.Services.ConditionalFormatting.Count | Should be 3
}
Close-ExcelPackage -NoSave $excel
}
Context "Formating (Set-ExcelRange or its alias set-Format) " {
Context "Formating (Set-ExcelRange or its alias Set-Format) " {
it "accepts Named Range, cells['Name'], cells['A1:Z9'], row, Worksheet + 'A1:Z9'" {
$excel = Get-Service | Export-Excel -Path test2.xlsx -WorksheetName Services -PassThru -AutoSize -DisplayPropertySet -RangeName servicerange -Title "Services on $Env:COMPUTERNAME"
{set-format $excel.Services.Names["serviceRange"] -Bold } | Should Not Throw
{Set-format $excel.Services.Names["serviceRange"] -Bold } | Should Not Throw
$excel.Services.cells["B2"].Style.Font.Bold | Should be $true
{Set-ExcelRange -Range $excel.Services.Cells["serviceRange"] -italic:$true } | Should not throw
$excel.Services.cells["C3"].Style.Font.Italic | Should be $true
{set-format $excel.Services.Row(4) -underline -Bold:$false } | Should not throw
{Set-format $excel.Services.Row(4) -underline -Bold:$false } | Should not throw
$excel.Services.cells["A4"].Style.Font.UnderLine | Should be $true
$excel.Services.cells["A4"].Style.Font.Bold | Should not be $true
{Set-ExcelRange $excel.Services.Cells["A3:B3"] -StrikeThru } | Should not throw
$excel.Services.cells["B3"].Style.Font.Strike | Should be $true
{Set-ExcelRange -WorkSheet $excel.Services -Range "A5:B6" -FontSize 8 } | Should not throw
{Set-ExcelRange -Worksheet $excel.Services -Range "A5:B6" -FontSize 8 } | Should not throw
$excel.Services.cells["A5"].Style.Font.Size | Should be 8
}
Close-ExcelPackage -NoSave $excel
it "Accepts Table, Table.Address , worksheet + Name, Column," {
$excel = Get-Service | Export-Excel -Path test2.xlsx -WorksheetName Services -PassThru -AutoNameRange -AutoSize -DisplayPropertySet -TableName servicetable -Title "Services on $Env:COMPUTERNAME"
{set-ExcelRange $excel.Services.Tables[0] -Italic } | Should not throw
{Set-ExcelRange $excel.Services.Tables[0] -Italic } | Should not throw
$excel.Services.cells["C3"].Style.Font.Italic | Should be $true
{set-format $excel.Services.Tables["ServiceTable"].Address -Underline } | Should not throw
{Set-format $excel.Services.Tables["ServiceTable"].Address -Underline } | Should not throw
$excel.Services.cells["C3"].Style.Font.UnderLine | Should be $true
{Set-ExcelRange -WorkSheet $excel.Services -Range "Name" -Bold } | Should not throw
{Set-ExcelRange -Worksheet $excel.Services -Range "Name" -Bold } | Should not throw
$excel.Services.cells["B4"].Style.Font.Bold | Should be $true
{$excel.Services.Column(3) | Set-ExcelRange -FontColor ([System.Drawing.Color]::Red) } | Should not throw
$excel.Services.cells["C4"].Style.Font.Color.Rgb | Should be "FFFF0000"

View File

@@ -1,5 +1,5 @@
#Requires -Modules Pester
if (-not (get-command Import-Excel -ErrorAction SilentlyContinue)) {
if (-not (Get-command Import-Excel -ErrorAction SilentlyContinue)) {
Import-Module $PSScriptRoot\..\ImportExcel.psd1
}
Describe "Remove Worksheet" {
@@ -29,11 +29,11 @@ John,20
}
it "Should throw about the Path".PadRight(87) {
{Remove-WorkSheet} | Should throw 'Remove-WorkSheet requires the and Excel file'
{Remove-Worksheet} | Should throw 'Remove-Worksheet requires the and Excel file'
}
it "Should delete Target2".PadRight(87) {
Remove-WorkSheet -Path $xlFile1 -WorksheetName Target2
Remove-Worksheet -Path $xlFile1 -WorksheetName Target2
$actual = Get-ExcelSheetInfo -Path $xlFile1
@@ -44,7 +44,7 @@ John,20
}
it "Should delete Sheet1".PadRight(87) {
Remove-WorkSheet -Path $xlFile1
Remove-Worksheet -Path $xlFile1
$actual = Get-ExcelSheetInfo -Path $xlFile1
@@ -55,7 +55,7 @@ John,20
}
it "Should delete multiple sheets".PadRight(87) {
Remove-WorkSheet -Path $xlFile1 -WorksheetName Target1, Sheet1
Remove-Worksheet -Path $xlFile1 -WorksheetName Target1, Sheet1
$actual = Get-ExcelSheetInfo -Path $xlFile1
@@ -66,7 +66,7 @@ John,20
it "Should delete sheet from multiple workbooks".PadRight(87) {
Get-ChildItem "TestDrive:\RemoveWorsheet*.xlsx" | Remove-WorkSheet
Get-ChildItem "TestDrive:\RemoveWorsheet*.xlsx" | Remove-Worksheet
$actual = Get-ExcelSheetInfo -Path $xlFile1

View File

@@ -48,27 +48,27 @@ Describe "Number format expansion and setting" {
$excel = 1..32 | ForEach-Object {$n} | Export-Excel -Path $path -show -WorksheetName s2 -PassThru
$ws = $excel.Workbook.Worksheets[1]
Set-ExcelRange -WorkSheet $ws -Range "A1" -numberFormat 'General'
Set-ExcelRange -WorkSheet $ws -Range "A2" -numberFormat 'Number'
Set-ExcelRange -WorkSheet $ws -Range "A3" -numberFormat 'Percentage'
Set-ExcelRange -WorkSheet $ws -Range "A4" -numberFormat 'Scientific'
Set-ExcelRange -WorkSheet $ws -Range "A5" -numberFormat 'Fraction'
Set-ExcelRange -WorkSheet $ws -Range "A6" -numberFormat 'Short Date'
Set-ExcelRange -WorkSheet $ws -Range "A7" -numberFormat 'Short Time'
Set-ExcelRange -WorkSheet $ws -Range "A8" -numberFormat 'Long Time'
Set-ExcelRange -WorkSheet $ws -Range "A9" -numberFormat 'Date-Time'
Set-ExcelRange -WorkSheet $ws -Range "A10" -numberFormat 'Currency'
Set-ExcelRange -WorkSheet $ws -Range "A11" -numberFormat 'Text'
Set-ExcelRange -WorkSheet $ws -Range "A12" -numberFormat 'h:mm AM/PM'
Set-ExcelRange -WorkSheet $ws -Range "A13" -numberFormat 'h:mm:ss AM/PM'
Set-ExcelRange -WorkSheet $ws -Range "A14" -numberFormat 'mm:ss'
Set-ExcelRange -WorkSheet $ws -Range "A15" -numberFormat '[h]:mm:ss'
Set-ExcelRange -WorkSheet $ws -Range "A16" -numberFormat 'mmss.0'
Set-ExcelRange -WorkSheet $ws -Range "A17" -numberFormat 'd-mmm-yy'
Set-ExcelRange -WorkSheet $ws -Range "A18" -numberFormat 'd-mmm'
Set-ExcelRange -WorkSheet $ws -Range "A19" -numberFormat 'mmm-yy'
Set-ExcelRange -WorkSheet $ws -Range "A20" -numberFormat '0'
Set-ExcelRange -WorkSheet $ws -Range "A21" -numberFormat '0.00'
Set-ExcelRange -Worksheet $ws -Range "A1" -numberFormat 'General'
Set-ExcelRange -Worksheet $ws -Range "A2" -numberFormat 'Number'
Set-ExcelRange -Worksheet $ws -Range "A3" -numberFormat 'Percentage'
Set-ExcelRange -Worksheet $ws -Range "A4" -numberFormat 'Scientific'
Set-ExcelRange -Worksheet $ws -Range "A5" -numberFormat 'Fraction'
Set-ExcelRange -Worksheet $ws -Range "A6" -numberFormat 'Short Date'
Set-ExcelRange -Worksheet $ws -Range "A7" -numberFormat 'Short Time'
Set-ExcelRange -Worksheet $ws -Range "A8" -numberFormat 'Long Time'
Set-ExcelRange -Worksheet $ws -Range "A9" -numberFormat 'Date-Time'
Set-ExcelRange -Worksheet $ws -Range "A10" -numberFormat 'Currency'
Set-ExcelRange -Worksheet $ws -Range "A11" -numberFormat 'Text'
Set-ExcelRange -Worksheet $ws -Range "A12" -numberFormat 'h:mm AM/PM'
Set-ExcelRange -Worksheet $ws -Range "A13" -numberFormat 'h:mm:ss AM/PM'
Set-ExcelRange -Worksheet $ws -Range "A14" -numberFormat 'mm:ss'
Set-ExcelRange -Worksheet $ws -Range "A15" -numberFormat '[h]:mm:ss'
Set-ExcelRange -Worksheet $ws -Range "A16" -numberFormat 'mmss.0'
Set-ExcelRange -Worksheet $ws -Range "A17" -numberFormat 'd-mmm-yy'
Set-ExcelRange -Worksheet $ws -Range "A18" -numberFormat 'd-mmm'
Set-ExcelRange -Worksheet $ws -Range "A19" -numberFormat 'mmm-yy'
Set-ExcelRange -Worksheet $ws -Range "A20" -numberFormat '0'
Set-ExcelRange -Worksheet $ws -Range "A21" -numberFormat '0.00'
Set-ExcelRange -Address $ws.Cells[ "A22"] -NumberFormat '#,##0'
Set-ExcelRange -Address $ws.Cells[ "A23"] -NumberFormat '#,##0.00'
Set-ExcelRange -Address $ws.Cells[ "A24"] -NumberFormat '#,'
@@ -131,8 +131,8 @@ Describe "Set-ExcelColumn, Set-ExcelRow and Set-ExcelRange" {
$r = Set-ExcelRow -PassThru -Worksheet $ws -StartColumn 3 -BorderAround Thin -Italic -Underline -FontSize 14 -Value {"=sum($columnName`2:$columnName$endrow)" } -VerticalAlignment Bottom
Set-ExcelRange -Address $excel.Workbook.Worksheets["Sheet1"].Cells["b3"] -HorizontalAlignment Right -VerticalAlignment Center -BorderAround Thick -BorderColor ([System.Drawing.Color]::Red) -StrikeThru
Set-ExcelRange -Address $excel.Workbook.Worksheets["Sheet1"].Cells["c3"] -BorderColor ([System.Drawing.Color]::Red) -BorderTop DashDot -BorderLeft DashDotDot -BorderBottom Dashed -BorderRight Dotted
Set-ExcelRange -WorkSheet $ws -Range "E3" -Bold:$false -FontShift Superscript -HorizontalAlignment Left
Set-ExcelRange -WorkSheet $ws -Range "E1" -ResetFont -HorizontalAlignment General -FontName "Courier New" -fontSize 9
Set-ExcelRange -Worksheet $ws -Range "E3" -Bold:$false -FontShift Superscript -HorizontalAlignment Left
Set-ExcelRange -Worksheet $ws -Range "E1" -ResetFont -HorizontalAlignment General -FontName "Courier New" -fontSize 9
Set-ExcelRange -Address $ws.Cells["E7"] -ResetFont -WrapText -BackgroundColor ([System.Drawing.Color]::AliceBlue) -BackgroundPattern DarkTrellis -PatternColor ([System.Drawing.Color]::Red) -NumberFormat "£#,###.00"
Set-ExcelRange -Address $ws.Column(1) -Width 0
if (-not $env:NoAutoSize) {
@@ -142,11 +142,11 @@ Describe "Set-ExcelColumn, Set-ExcelRow and Set-ExcelRange" {
#Test alias
Set-Format -Address $ws.row(5) -Height 0
$rr = $r.row
Set-ExcelRange -WorkSheet $ws -Range "B$rr" -Value "Total"
Set-ExcelRange -Worksheet $ws -Range "B$rr" -Value "Total"
$BadHideWarnvar = $null
Set-ExcelRange -WorkSheet $ws -Range "D$rr" -Formula "=E$rr/C$rr" -Hidden -WarningVariable "BadHideWarnvar" -WarningAction SilentlyContinue
Set-ExcelRange -Worksheet $ws -Range "D$rr" -Formula "=E$rr/C$rr" -Hidden -WarningVariable "BadHideWarnvar" -WarningAction SilentlyContinue
$rr ++
Set-ExcelRange -WorkSheet $ws -Range "B$rr" -Value ([datetime]::Now)
Set-ExcelRange -Worksheet $ws -Range "B$rr" -Value ([datetime]::Now)
Close-ExcelPackage $excel -Calculate

View File

@@ -15,11 +15,11 @@ Describe "Data validation and protection" {
Context "Data Validation rules" {
BeforeAll {
Remove-Item $path -ErrorAction SilentlyContinue
$excelPackage = $Data | export-excel -WorksheetName "Sales" -path $path -PassThru
$excelPackage = $Data | Export-excel -WorksheetName "Sales" -path $path -PassThru
$excelPackage = @('Chisel','Crowbar','Drill','Hammer','Nails','Saw','Screwdriver','Wrench') |
Export-excel -ExcelPackage $excelPackage -WorksheetName Values -PassThru
$VParams = @{WorkSheet = $excelPackage.sales; ShowErrorMessage=$true; ErrorStyle='stop'; ErrorTitle='Invalid Data' }
$VParams = @{Worksheet = $excelPackage.sales; ShowErrorMessage=$true; ErrorStyle='stop'; ErrorTitle='Invalid Data' }
Add-ExcelDataValidationRule @VParams -Range 'B2:B1001' -ValidationType List -Formula 'values!$a$1:$a$10' -ErrorBody "You must select an item from the list.`r`nYou can add to the list on the values page" #Bucket
Add-ExcelDataValidationRule @VParams -Range 'E2:E1001' -ValidationType Integer -Operator between -Value 0 -Value2 10000 -ErrorBody 'Quantity must be a whole number between 0 and 10000'
Close-ExcelPackage -ExcelPackage $excelPackage