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

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