mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-10 21:33:16 +00:00
fix message in merge, improve pester example
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
|
[CmdletBinding(DefaultParameterSetName = 'Default')]
|
||||||
[CmdletBinding(DefaultParameterSetName = 'Default')]
|
|
||||||
param(
|
param(
|
||||||
[Parameter(Position=0)]
|
[Parameter(Position=0)]
|
||||||
[string]$XLFile,
|
[string]$XLFile,
|
||||||
@@ -94,10 +93,12 @@ $testResults = foreach ($test in $resultXML.'test-suite'.results.'test-suite') {
|
|||||||
New-Object -TypeName psobject -Property ([ordered]@{
|
New-Object -TypeName psobject -Property ([ordered]@{
|
||||||
Machine = $machine ; OS = $os
|
Machine = $machine ; OS = $os
|
||||||
Date = $startDate ; Time = $startTime
|
Date = $startDate ; Time = $startTime
|
||||||
Executed = $_.executed ; Result = $_.result ; Duration = $_.time
|
Executed = $(if ($_.executed -eq 'True') {1})
|
||||||
File = $testPs1File; Group = $Describe ; SubGroup = $Context
|
Success = $(if ($_.success -eq 'True') {1})
|
||||||
Test =($_.Description -replace '\s{2,}', ' ')
|
Duration = $_.time
|
||||||
FullDesc = '=Group&" "&SubGroup&" "&Test'})
|
File = $testPs1File; Group = $Describe
|
||||||
|
SubGroup = $Context ; Name =($_.Description -replace '\s{2,}', ' ')
|
||||||
|
Result = $_.result ; FullDesc = '=Group&" "&SubGroup&" "&Test'})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,10 +110,12 @@ $testResults = foreach ($test in $resultXML.'test-suite'.results.'test-suite') {
|
|||||||
New-Object -TypeName psobject -Property ([ordered]@{
|
New-Object -TypeName psobject -Property ([ordered]@{
|
||||||
Machine = $machine ; OS = $os
|
Machine = $machine ; OS = $os
|
||||||
Date = $startDate ; Time = $startTime
|
Date = $startDate ; Time = $startTime
|
||||||
Executed = $_.executed ; Result = $_.result ; Duration = $_.time
|
Executed = $(if ($_.executed -eq 'True') {1})
|
||||||
File = $testPs1File; Group = $Describe ; SubGroup = $null
|
Success = $(if ($_.success -eq 'True') {1})
|
||||||
Test =($_.Description -replace '\s{2,}', ' ')
|
Duration = $_.time
|
||||||
FullDesc = '=Group&" "&Test'})
|
File = $testPs1File; Group = $Describe
|
||||||
|
SubGroup = $null ; Name =($_.Description -replace '\s{2,}', ' ')
|
||||||
|
Result = $_.result ; FullDesc = '=Group&" "&Test'})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,20 +125,20 @@ $clearSheet = -not $Append
|
|||||||
$excel = $testResults | Export-Excel -Path $xlFile -WorkSheetname $WorkSheetName -ClearSheet:$clearSheet -Append:$append -PassThru -BoldTopRow -FreezeTopRow -AutoSize -AutoFilter -AutoNameRange
|
$excel = $testResults | Export-Excel -Path $xlFile -WorkSheetname $WorkSheetName -ClearSheet:$clearSheet -Append:$append -PassThru -BoldTopRow -FreezeTopRow -AutoSize -AutoFilter -AutoNameRange
|
||||||
$ws = $excel.Workbook.Worksheets[$WorkSheetName]
|
$ws = $excel.Workbook.Worksheets[$WorkSheetName]
|
||||||
|
|
||||||
<# Worksheet should look like ...
|
<# Worksheet should look like ..
|
||||||
|A |B |C D |E |F |G |H |I |J |K |L
|
|A |B |C D |E |F |G |H |I |J |K |L |M
|
||||||
1|Machine |OS |Date Time |Executed |Result |Duration |File |Group |SubGroup |Test |FullDescription
|
1|Machine |OS |Date Time |Executed |Success |Duration |File |Group |SubGroup |Name |Result |FullDescription
|
||||||
2|Flatfish |Name_Version |[run started] |Boolean |Success |In seconds |xx.ps1 |Describe |Context |It |Desc_Context_It
|
2|Flatfish |Name_Version |[run started] |Boolean |Boolean |In seconds |xx.ps1 |Describe |Context |It |Success |Desc_Context_It
|
||||||
#>
|
#>
|
||||||
|
|
||||||
#Display Date as a date, not a date time
|
#Display Date as a date, not a date time
|
||||||
Set-Column -Worksheet $ws -Column 3 -NumberFormat 'Short Date' # -AutoSize
|
Set-Column -Worksheet $ws -Column 3 -NumberFormat 'Short Date' # -AutoSize
|
||||||
|
|
||||||
#Hide columns G to K (the file and the parts of the description, and the duration)5
|
#Hide columns E to J (Executed, Success, Duration, File, Group and Subgroup)
|
||||||
(7..10) + 5 | ForEach-Object {Set-ExcelColumn -Worksheet $ws -Column $_ -Hide }
|
(5..10) | ForEach-Object {Set-ExcelColumn -Worksheet $ws -Column $_ -Hide }
|
||||||
|
|
||||||
#Use conditional formatting to make Failures red, and Successes green (skipped remains black ) ... and save
|
#Use conditional formatting to make Failures red, and Successes green (skipped remains black ) ... and save
|
||||||
$endRow = $ws.Dimension.End.Row
|
$endRow = $ws.Dimension.End.Row
|
||||||
Add-ConditionalFormatting -WorkSheet $ws -range "f2:f$endrow" -RuleType ContainsText -ConditionValue "Failure" -BackgroundPattern None -ForegroundColor Red -Bold
|
Add-ConditionalFormatting -WorkSheet $ws -range "L2:L$endrow" -RuleType ContainsText -ConditionValue "Failure" -BackgroundPattern None -ForegroundColor Red -Bold
|
||||||
Add-ConditionalFormatting -WorkSheet $ws -range "f2:f$endRow" -RuleType ContainsText -ConditionValue "Success" -BackgroundPattern None -ForeGroundColor Green
|
Add-ConditionalFormatting -WorkSheet $ws -range "L2:L$endRow" -RuleType ContainsText -ConditionValue "Success" -BackgroundPattern None -ForeGroundColor Green
|
||||||
Close-ExcelPackage -ExcelPackage $excel -Show:$show
|
Close-ExcelPackage -ExcelPackage $excel -Show:$show
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
function Merge-MultipleSheets {
|
function Merge-MultipleSheets {
|
||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")]
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification="False positives when initializing variable in begin block")]
|
||||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification="MultipleSheet would be incorrect")]
|
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification="MultipleSheet would be incorrect")]
|
||||||
|
|||||||
@@ -118,7 +118,7 @@
|
|||||||
$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 ($NoHeader -and "Name" -eq $Key) {$Key = "p1"}
|
||||||
if ($headings -notcontains $Key -and
|
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 }
|
('*' -ne $Key)) {Write-Warning -Message "You need to specify one of the headings in the sheet '$Worksheet2' as a key." ; return }
|
||||||
foreach ($p in $Property) { $propList += ($headings.where({$_ -like $p}) )}
|
foreach ($p in $Property) { $propList += ($headings.where({$_ -like $p}) )}
|
||||||
foreach ($p in $ExcludeProperty) { $propList = $propList.where({$_ -notlike $p}) }
|
foreach ($p in $ExcludeProperty) { $propList = $propList.where({$_ -notlike $p}) }
|
||||||
if (($propList -notcontains $Key) -and
|
if (($propList -notcontains $Key) -and
|
||||||
|
|||||||
Reference in New Issue
Block a user