mirror of
https://github.com/dfinke/ImportExcel.git
synced 2026-01-07 19:13:43 +00:00
See readme.md for details
This commit is contained in:
@@ -197,6 +197,7 @@ Describe ExportExcel {
|
||||
Link2 = "https://github.com/dfinke/ImportExcel"
|
||||
Link3 = "xl://internal/sheet1!A1"
|
||||
Link4 = "xl://internal/sheet1!C5"
|
||||
Link5 = (New-Object -TypeName OfficeOpenXml.ExcelHyperLink -ArgumentList "Sheet1!E2" , "Display Text")
|
||||
Process = (Get-Process -Id $PID)
|
||||
TimeSpan = [datetime]::Now.Subtract([datetime]::Today)
|
||||
} | Export-Excel -NoNumberConversion IPAddress, StrLeadZero, StrAltPhone2 -Path $path -Calculate -WarningVariable $warnVar
|
||||
@@ -211,7 +212,7 @@ Describe ExportExcel {
|
||||
$ws = $Excel.Workbook.Worksheets[1]
|
||||
it "Created the worksheet with the expected name, number of rows and number of columns " {
|
||||
$ws.Name | Should be "sheet1"
|
||||
$ws.Dimension.Columns | Should be 26
|
||||
$ws.Dimension.Columns | Should be 27
|
||||
$ws.Dimension.Rows | Should be 2
|
||||
}
|
||||
it "Set a date in Cell A2 " {
|
||||
@@ -247,6 +248,8 @@ Describe ExportExcel {
|
||||
$ws.Cells[2, 24].Hyperlink.Scheme | Should be "xl"
|
||||
$ws.Cells[2, 24].Hyperlink.ReferenceAddress | Should be "sheet1!c5"
|
||||
$ws.Cells[2, 24].Hyperlink.Display | Should be "sheet1!c5"
|
||||
$ws.Cells[2, 25].Hyperlink.ReferenceAddress | Should be "sheet1!E2"
|
||||
$ws.Cells[2, 25].Hyperlink.Display | Should be "Display Text"
|
||||
}
|
||||
it "Processed thousands according to local settings (Cells H2 and I2) " {
|
||||
if ((Get-Culture).NumberFormat.NumberGroupSeparator -EQ ",") {
|
||||
@@ -271,12 +274,12 @@ Describe ExportExcel {
|
||||
($ws.Cells[2, 20].Value -is [valuetype] ) | Should be $true
|
||||
}
|
||||
it "Converted a nested object to a string (Y2) " {
|
||||
$ws.Cells[2, 25].Value | should match '^System\.Diagnostics\.Process\s+\(.*\)$'
|
||||
$ws.Cells[2, 26].Value | should match '^System\.Diagnostics\.Process\s+\(.*\)$'
|
||||
}
|
||||
it "Processed a timespan object (Z2) " {
|
||||
$ws.cells[2, 26].Value.ToOADate() | should beGreaterThan 0
|
||||
$ws.cells[2, 26].Value.ToOADate() | should beLessThan 1
|
||||
$ws.cells[2, 26].Style.Numberformat.Format | should be '[h]:mm:ss'
|
||||
$ws.cells[2, 27].Value.ToOADate() | should beGreaterThan 0
|
||||
$ws.cells[2, 27].Value.ToOADate() | should beLessThan 1
|
||||
$ws.cells[2, 27].Style.Numberformat.Format | should be '[h]:mm:ss'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -759,7 +762,7 @@ 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
|
||||
$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
|
||||
@@ -768,7 +771,7 @@ Describe ExportExcel {
|
||||
$ParamChk1[2] | Should be "Worksheet"
|
||||
$ParamChk2.count | Should be 1
|
||||
$ParamChk2[0] | Should be "Header"
|
||||
}
|
||||
}
|
||||
#Test Invoke-Sum
|
||||
$data = Invoke-Sum (Get-Process) Company Handles, PM, VirtualMemorySize
|
||||
it "Used Invoke-Sum to create a data set " {
|
||||
|
||||
@@ -37,8 +37,8 @@ Describe "Number format expansion and setting" {
|
||||
Context "Expand-NumberFormat function" {
|
||||
It "Expanded named number formats as expected " {
|
||||
$r = [regex]::Escape([cultureinfo]::CurrentCulture.NumberFormat.CurrencySymbol)
|
||||
|
||||
Expand-NumberFormat 'Currency' | Should match "^[$r\(\)\[\]RED0#\?\-;,.]+$"
|
||||
|
||||
Expand-NumberFormat 'Currency' | Should match "^[$r\(\)\[\]RED0#\?\-;,.]+$"
|
||||
Expand-NumberFormat 'Number' | Should be "0.00"
|
||||
Expand-NumberFormat 'Percentage' | Should be "0.00%"
|
||||
Expand-NumberFormat 'Scientific' | Should be "0.00E+00"
|
||||
@@ -268,20 +268,72 @@ Describe "Set-Column, Set-Row and Set Format" {
|
||||
|
||||
Describe "Conditional Formatting" {
|
||||
BeforeAll {
|
||||
Remove-Item $path
|
||||
$data = Get-Process | where company | select company,name,pm,handles,*mem*
|
||||
Remove-Item $path
|
||||
$data = Get-Process | Where-Object company | Select-Object company,name,pm,handles,*mem*
|
||||
$cfmt = New-ConditionalFormattingIconSet -Range "c:c" -ConditionalFormat ThreeIconSet -IconType Arrows
|
||||
$data | Export-Excel -path $Path -AutoSize -ConditionalFormat $cfmt
|
||||
$excel = Open-ExcelPackage -Path $path
|
||||
$excel = Open-ExcelPackage -Path $path
|
||||
$ws = $excel.Workbook.Worksheets[1]
|
||||
}
|
||||
Context "Using a pre-prepared 3 Arrows rule" {
|
||||
it "Set the right type, IconSet and range " {
|
||||
$ws.ConditionalFormatting[0].IconSet | Should be "Arrows"
|
||||
$ws.ConditionalFormatting[0].Address.Address | Should be "c:c"
|
||||
$ws.ConditionalFormatting[0].IconSet | Should be "Arrows"
|
||||
$ws.ConditionalFormatting[0].Address.Address | Should be "c:c"
|
||||
$ws.ConditionalFormatting[0].Type.ToString() | Should be "ThreeIconSet"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$path = "$Env:TEMP\test.xlsx"
|
||||
$data2 = ConvertFrom-Csv -InputObject @"
|
||||
ID,Product,Quantity,Price,Total
|
||||
12001,Nails,37,3.99,147.63
|
||||
12002,Hammer,5,12.10,60.5
|
||||
12003,Saw,12,15.37,184.44
|
||||
12010,Drill,20,8,160
|
||||
12011,Crowbar,7,23.48,164.36
|
||||
12001,Nails,53,3.99,211.47
|
||||
12002,Hammer,6,12.10,72.60
|
||||
12003,Saw,10,15.37,153.70
|
||||
12010,Drill,10,8,80
|
||||
12012,Pliers,2,14.99,29.98
|
||||
12001,Nails,20,3.99,79.80
|
||||
12002,Hammer,2,12.10,24.20
|
||||
12010,Drill,11,8,88
|
||||
12012,Pliers,3,14.99,44.97
|
||||
"@
|
||||
|
||||
Describe "Table Formatting" {
|
||||
BeforeAll {
|
||||
Remove-Item $path
|
||||
$excel = $data2 | Export-excel -path $path -WorksheetName Hardware -AutoNameRange -AutoSize -BoldTopRow -FreezeTopRow -PassThru
|
||||
$ws = $excel.Workbook.Worksheets[1]
|
||||
Set-Column -Worksheet $ws -Column 4 -NumberFormat 'Currency'
|
||||
Set-Column -Worksheet $ws -Column 5 -NumberFormat 'Currency'
|
||||
Add-ExcelTable -Range $ws.cells[$($ws.Dimension.address)] -TableStyle Light1 -TableName HardwareTable -ShowTotal -ShowFirstColumn
|
||||
|
||||
$PtDef =New-PivotTableDefinition -PivotTableName Totals -PivotRows Product -PivotData @{"Total"="Sum"} -PivotNumberFormat Currency -PivotTotals None -PivotTableSyle Dark2
|
||||
Export-excel -ExcelPackage $excel -WorksheetName Hardware -PivotTableDefinition $PtDef
|
||||
$excel= Open-ExcelPackage -Path $path
|
||||
$ws1 = $excel.Workbook.Worksheets["Hardware"]
|
||||
$ws2 = $excel.Workbook.Worksheets["Totals"]
|
||||
}
|
||||
Context "Setting and not clearing when Export-Excel touches the file again."{
|
||||
it "Set the Table Options " {
|
||||
$ws1.Tables[0].Address.Address | should be "A1:E16"
|
||||
$ws1.Tables[0].Name | should be "HardwareTable"
|
||||
$ws1.Tables[0].ShowFirstColumn | should be $true
|
||||
$ws1.Tables[0].ShowLastColumn | should not be $true
|
||||
$ws1.Tables[0].ShowTotal | should be $true
|
||||
$ws1.Tables[0].StyleName | should be "TableStyleLight1"
|
||||
$ws1.Cells["D4"].Style.Numberformat.Format | Should match ([regex]::Escape([cultureinfo]::CurrentCulture.NumberFormat.CurrencySymbol))
|
||||
$ws1.Cells["E5"].Style.Numberformat.Format | Should match ([regex]::Escape([cultureinfo]::CurrentCulture.NumberFormat.CurrencySymbol))
|
||||
$ws1.Cells["E5"].Style.Numberformat.Format | Should match ([regex]::Escape([cultureinfo]::CurrentCulture.NumberFormat.CurrencySymbol))
|
||||
}
|
||||
it "Set the Pivot Options " {
|
||||
$ws2.PivotTables[0].DataFields[0].Format | Should match ([regex]::Escape([cultureinfo]::CurrentCulture.NumberFormat.CurrencySymbol))
|
||||
$ws2.PivotTables[0].ColumGrandTotals | Should be $false
|
||||
$ws2.PivotTables[0].StyleName | Should be "PivotStyleDark2"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user