mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Color constants are now [color] objects, not string for V6 compat.
This commit is contained in:
@@ -113,7 +113,7 @@
|
||||
elseif ($Range -is [string]) {Write-Warning -Message "The range pararameter you have specified also needs a worksheet parameter."}
|
||||
|
||||
if ($ResetFont) {
|
||||
$Range.Style.Font.Color.SetColor("Black")
|
||||
$Range.Style.Font.Color.SetColor( ([System.Drawing.Color]::Black))
|
||||
$Range.Style.Font.Bold = $false
|
||||
$Range.Style.Font.Italic = $false
|
||||
$Range.Style.Font.UnderLine = $false
|
||||
|
||||
@@ -51,7 +51,7 @@ Describe "Compare Worksheet" {
|
||||
|
||||
Context "Setting the background to highlight different rows, use of grid view." {
|
||||
BeforeAll {
|
||||
Compare-WorkSheet "$env:temp\Server1.xlsx" "$env:temp\Server2.xlsx" -BackgroundColor LightGreen -GridView
|
||||
Compare-WorkSheet "$env:temp\Server1.xlsx" "$env:temp\Server2.xlsx" -BackgroundColor ([System.Drawing.Color]::LightGreen) -GridView
|
||||
Start-Sleep -sec 5; [System.Windows.Forms.SendKeys]::Sendwait("%{F4}")
|
||||
$xl1 = Open-ExcelPackage -Path "$env:temp\Server1.xlsx"
|
||||
$xl2 = Open-ExcelPackage -Path "$env:temp\Server2.xlsx"
|
||||
@@ -78,7 +78,7 @@ Describe "Compare Worksheet" {
|
||||
|
||||
Context "Setting the forgound to highlight changed properties" {
|
||||
BeforeAll {
|
||||
$null = compare-WorkSheet "$env:temp\Server1.xlsx" "$env:temp\Server2.xlsx" -AllDataBackgroundColor white -BackgroundColor LightGreen -FontColor DarkRed
|
||||
$null = compare-WorkSheet "$env:temp\Server1.xlsx" "$env:temp\Server2.xlsx" -AllDataBackgroundColor([System.Drawing.Color]::white) -BackgroundColor ([System.Drawing.Color]::LightGreen) -FontColor ([System.Drawing.Color]::DarkRed)
|
||||
$xl1 = Open-ExcelPackage -Path "$env:temp\Server1.xlsx"
|
||||
$xl2 = Open-ExcelPackage -Path "$env:temp\Server2.xlsx"
|
||||
$s1Sheet = $xl1.Workbook.Worksheets[1]
|
||||
@@ -121,7 +121,7 @@ Describe "Compare Worksheet" {
|
||||
$s[10].ServiceType = "Changed should not matter"
|
||||
$s | Select-Object -Property ServiceName, DisplayName, StartType, ServiceType | Export-Excel -Path $env:temp\server2.xlsx -WorkSheetname server2
|
||||
#Assume default worksheet name, (sheet1) and column header for key ("name")
|
||||
$comp = compare-WorkSheet "$env:temp\Server1.xlsx" "$env:temp\Server2.xlsx" -WorkSheetName Server1,Server2 -Key ServiceName -Property DisplayName,StartType -AllDataBackgroundColor AliceBlue -BackgroundColor White -FontColor Red | Sort-Object _row,_file
|
||||
$comp = compare-WorkSheet "$env:temp\Server1.xlsx" "$env:temp\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 "$env:temp\Server1.xlsx"
|
||||
$xl2 = Open-ExcelPackage -Path "$env:temp\Server2.xlsx"
|
||||
$s1Sheet = $xl1.Workbook.Worksheets["server1"]
|
||||
|
||||
@@ -355,13 +355,7 @@ Describe ExportExcel {
|
||||
|
||||
Context "#Example 5 # Adding a single conditional format " {
|
||||
#Test New-ConditionalText builds correctly
|
||||
$ct = New-ConditionalText -ConditionalType GreaterThan 525 -ConditionalTextColor DarkRed -BackgroundColor LightPink
|
||||
it "Created a Conditional format description " {
|
||||
$ct.BackgroundColor -is [System.Drawing.Color] | Should be $true
|
||||
$ct.ConditionalTextColor -is [System.Drawing.Color] | Should be $true
|
||||
$ct.ConditionalType -in [enum]::GetNames( [OfficeOpenXml.ConditionalFormatting.eExcelConditionalFormattingRuleType] ) |
|
||||
Should be $true
|
||||
}
|
||||
$ct = New-ConditionalText -ConditionalType GreaterThan 525 -ConditionalTextColor ([System.Drawing.Color]::DarkRed) -BackgroundColor ([System.Drawing.Color]::LightPink)
|
||||
|
||||
$path = "$env:TEMP\Test.xlsx"
|
||||
Remove-item -Path $path -ErrorAction SilentlyContinue
|
||||
@@ -398,8 +392,8 @@ Describe ExportExcel {
|
||||
#Testing -Passthrough
|
||||
$Excel = Get-Service | Select-Object Name, Status, DisplayName, ServiceName |
|
||||
Export-Excel $path -PassThru -ConditionalText $(
|
||||
New-ConditionalText Stop DarkRed LightPink
|
||||
New-ConditionalText Running Blue Cyan
|
||||
New-ConditionalText Stop ([System.Drawing.Color]::DarkRed) ([System.Drawing.Color]::LightPink)
|
||||
New-ConditionalText Running ([System.Drawing.Color]::Blue) ([System.Drawing.Color]::Cyan)
|
||||
)
|
||||
$ws = $Excel.Workbook.Worksheets[1]
|
||||
it "Added two blocks of conditional formating for the data range " {
|
||||
@@ -649,7 +643,7 @@ Describe ExportExcel {
|
||||
$warnvar = $null
|
||||
#Test create two data pages; as part of adding the second give both their own pivot table, test -autosize switch
|
||||
Get-Service | Select-Object -Property Status, Name, DisplayName, StartType, CanPauseAndContinue | Export-Excel -Path $path -AutoSize -TableName "All Services" -TableStyle Medium1 -WarningAction SilentlyContinue -WarningVariable warnvar
|
||||
Get-Process | Select-Object -Property Name, Company, Handles, CPU, VM | Export-Excel -Path $path -AutoSize -WorkSheetname 'sheet2' -TableName "Processes" -TableStyle Light1 -Title "Processes" -TitleFillPattern Solid -TitleBackgroundColor AliceBlue -TitleBold -TitleSize 22 -PivotTableDefinition $ptDef
|
||||
Get-Process | Select-Object -Property Name, Company, Handles, CPU, VM | Export-Excel -Path $path -AutoSize -WorkSheetname 'sheet2' -TableName "Processes" -TableStyle Light1 -Title "Processes" -TitleFillPattern Solid -TitleBackgroundColor ([System.Drawing.Color]::AliceBlue) -TitleBold -TitleSize 22 -PivotTableDefinition $ptDef
|
||||
$Excel = Open-ExcelPackage $path
|
||||
$ws1 = $Excel.Workbook.Worksheets["Sheet1"]
|
||||
$ws2 = $Excel.Workbook.Worksheets["Sheet2"]
|
||||
@@ -722,10 +716,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 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 Red -Bold -Italic -Underline -BackgroundColor Beige -BackgroundPattern LightUp -PatternColor 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
|
||||
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
|
||||
@@ -857,7 +851,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 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 " {
|
||||
@@ -916,7 +910,7 @@ Describe ExportExcel {
|
||||
Select-Object -Property Name, @{n="TotalPm";e={($_.group | Measure-Object -sum -Property pm).sum }} |
|
||||
Export-Excel -NoHeader -AutoNameRange -path $path -ReturnRange -PieChart -ShowPercent
|
||||
$Cf = New-ConditionalFormattingIconSet -Range ($range -replace "^.*:","B2:") -ConditionalFormat ThreeIconSet -Reverse -IconType Flags
|
||||
$ct = New-ConditionalText -Text "Microsoft" -ConditionalTextColor red -BackgroundColor AliceBlue -ConditionalType ContainsText
|
||||
$ct = New-ConditionalText -Text "Microsoft" -ConditionalTextColor ([System.Drawing.Color]::Red) -BackgroundColor([System.Drawing.Color]::AliceBlue) -ConditionalType ContainsText
|
||||
it "Created the Conditional formatting rules " {
|
||||
$cf.Formatter | Should be "ThreeIconSet"
|
||||
$cf.IconType | Should be "Flags"
|
||||
|
||||
@@ -10,7 +10,7 @@ Banana, London , 300, 200
|
||||
Orange, Paris, 600, 500
|
||||
Banana, Paris, 300, 200
|
||||
Apple, New York, 1200,700
|
||||
"@ | Export-Excel -Path $path -TableStyle Medium13 -tablename "RawData" -ConditionalFormat @{Range="C2:C7"; DataBarColor="Green"} -ExcelChartDefinition @{ChartType="Doughnut";XRange="A2:B7"; YRange="C2:C7"; width=800; } -PivotTableDefinition @{Sales=@{
|
||||
"@ | Export-Excel -Path $path -TableStyle Medium13 -tablename "RawData" -ConditionalFormat @{Range="C2:C7"; DataBarColor=([System.Drawing.Color]::Green)} -ExcelChartDefinition @{ChartType="Doughnut";XRange="A2:B7"; YRange="C2:C7"; width=800; } -PivotTableDefinition @{Sales=@{
|
||||
PivotRows="City"; PivotColumns="Product"; PivotData=@{Gross="Sum";Net="Sum"}; PivotNumberFormat="$#,##0.00"; PivotTotals="Both"; PivotTableSyle="Medium12"; Activate=$true
|
||||
PivotChartDefinition=@{Title="Gross and net by city and product"; ChartType="ColumnClustered"; Column=6; Width=600; Height=360; YMajorUnit=500; YMinorUnit=100; YAxisNumberformat="$#,##0"; LegendPosition="Bottom"}}}
|
||||
|
||||
|
||||
@@ -34,10 +34,10 @@ Describe "Creating small named ranges with hyperlinks" {
|
||||
$cf.Icon2.Type = $cf.Icon3.Type = "Num"
|
||||
$cf.Icon2.Value = 0
|
||||
$cf.Icon3.Value = 1
|
||||
Add-ConditionalFormatting -Address $worksheet.cells["FinishPosition"] -RuleType Equal -ConditionValue 1 -ForeGroundColor Purple -Bold -Priority 1 -StopIfTrue #Test Priority and stopIfTrue and using range name
|
||||
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 Red -Background 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
|
||||
$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 #Test conditional text rules in conditional format (orignally icon sets only )
|
||||
|
||||
@@ -30,7 +30,7 @@ Describe "Join Worksheet" {
|
||||
$data2 | Export-Excel -Path $path -WorkSheetname Abingdon
|
||||
$data3 | Export-Excel -Path $path -WorkSheetname Banbury
|
||||
$ptdef = New-PivotTableDefinition -PivotTableName "SummaryPivot" -PivotRows "Store" -PivotColumns "Product" -PivotData @{"Total"="SUM"} -IncludePivotChart -ChartTitle "Sales Breakdown" -ChartType ColumnStacked -ChartColumn 10
|
||||
Join-Worksheet -Path $path -WorkSheetName "Total" -Clearsheet -FromLabel "Store" -TableName "SummaryTable" -TableStyle Light1 -AutoSize -BoldTopRow -FreezePane 2,1 -Title "Store Sales Summary" -TitleBold -TitleSize 14 -TitleBackgroundColor AliceBlue -PivotTableDefinition $ptdef
|
||||
Join-Worksheet -Path $path -WorkSheetName "Total" -Clearsheet -FromLabel "Store" -TableName "SummaryTable" -TableStyle Light1 -AutoSize -BoldTopRow -FreezePane 2,1 -Title "Store Sales Summary" -TitleBold -TitleSize 14 -TitleBackgroundColor ([System.Drawing.Color]::AliceBlue) -PivotTableDefinition $ptdef
|
||||
|
||||
$excel = Export-Excel -path $path -WorkSheetname SummaryPivot -Activate -NoTotalsInPivot -PivotDataToColumn -HideSheet * -UnHideSheet "Total","SummaryPivot" -PassThru
|
||||
# Open-ExcelPackage -Path $path
|
||||
|
||||
@@ -19,7 +19,7 @@ describe "Consistent passing of ranges." {
|
||||
$warnvar | should beNullOrEmpty
|
||||
$excel.Services.ConditionalFormatting.Count | Should be 3
|
||||
{Add-ConditionalFormatting "Status" -WorkSheet $excel.Services `
|
||||
-ForeGroundColor Green -RuleType ContainsText -ConditionValue "Running"} | Should not throw
|
||||
-ForeGroundColor ([System.Drawing.Color]::Green) -RuleType ContainsText -ConditionValue "Running"} | Should not throw
|
||||
$excel.Services.ConditionalFormatting.Count | Should be 4
|
||||
}
|
||||
Close-ExcelPackage -NoSave $excel
|
||||
@@ -32,7 +32,7 @@ describe "Consistent passing of ranges." {
|
||||
-Bold -RuleType ContainsText -ConditionValue "windows" } | Should not throw
|
||||
$excel.Services.ConditionalFormatting.Count | Should be 2
|
||||
{Add-ConditionalFormatting -WorkSheet $excel.Services -Address "a:a" `
|
||||
-RuleType ContainsText -ConditionValue "stopped" -ForeGroundColor Red } | Should not throw
|
||||
-RuleType ContainsText -ConditionValue "stopped" -ForeGroundColor ([System.Drawing.Color]::Red) } | Should not throw
|
||||
$excel.Services.ConditionalFormatting.Count | Should be 3
|
||||
}
|
||||
Close-ExcelPackage -NoSave $excel
|
||||
@@ -62,7 +62,7 @@ describe "Consistent passing of ranges." {
|
||||
$excel.Services.cells["C3"].Style.Font.UnderLine | Should be $true
|
||||
{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 red } | Should not throw
|
||||
{$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"
|
||||
}
|
||||
Close-ExcelPackage -NoSave $excel
|
||||
|
||||
@@ -135,13 +135,13 @@ Describe "Set-ExcelColumn, Set-ExcelRow and Set-ExcelRange" {
|
||||
$excel = $data| Export-Excel -Path $path -AutoNameRange -PassThru
|
||||
$ws = $excel.Workbook.Worksheets["Sheet1"]
|
||||
|
||||
$c = Set-ExcelColumn -PassThru -Worksheet $ws -Heading "Total" -Value "=Quantity*Price" -NumberFormat "£#,###.00" -FontColor Blue -Bold -HorizontalAlignment Right -VerticalAlignment Top
|
||||
$c = Set-ExcelColumn -PassThru -Worksheet $ws -Heading "Total" -Value "=Quantity*Price" -NumberFormat "£#,###.00" -FontColor ([System.Drawing.Color]::Blue) -Bold -HorizontalAlignment Right -VerticalAlignment Top
|
||||
$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 Red -StrikeThru
|
||||
Set-ExcelRange -Address $excel.Workbook.Worksheets["Sheet1"].Cells["c3"] -BorderColor Red -BorderTop DashDot -BorderLeft DashDotDot -BorderBottom Dashed -BorderRight Dotted
|
||||
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 -Address $ws.Cells["E7"] -ResetFont -WrapText -BackgroundColor AliceBlue -BackgroundPattern DarkTrellis -PatternColor Red -NumberFormat "£#,###.00"
|
||||
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
|
||||
Set-ExcelRange -Address $ws.Column(2) -AutoFit
|
||||
Set-ExcelRange -Address $ws.Cells["E:E"] -AutoFit
|
||||
|
||||
Reference in New Issue
Block a user