From a3c2a92e33b3ae480bfeae8c07fd4df038f8b6ef Mon Sep 17 00:00:00 2001 From: Brun Date: Wed, 20 Sep 2017 13:56:06 -0400 Subject: [PATCH] Header formatting fix when Title is used (Issue #182) --- Export-Excel.ps1 | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index cfbcddce..f49d853c 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -41,7 +41,7 @@ Function Export-Excel { '#,##0.00' # number with 2 decimal places and thousand separator and money symbol - '€#,##0.00' + '€#,##0.00' # percentage (1 = 100%, 0.01 = 1%) '0%' @@ -498,8 +498,14 @@ Function Export-Excel { } } - $startAddress=$ws.Dimension.Start.Address - $dataRange="{0}:{1}" -f $startAddress, $ws.Dimension.End.Address + if ($Title) { + $startAddress = "A2" + } + else { + $startAddress = $ws.Dimension.Start.Address + } + + $dataRange = "{0}:{1}" -f $startAddress, $ws.Dimension.End.Address Write-Debug "Data Range '$dataRange'" @@ -526,10 +532,6 @@ Function Export-Excel { $pivotTableDataName=$WorkSheetname + 'PivotTableData' - if ($Title) { - $startAddress = 'A2' - } - $pivotTable = $wsPivot.PivotTables.Add($wsPivot.Cells['A1'], $ws.Cells[$dataRange], $pivotTableDataName) if ($PivotRows) { @@ -607,7 +609,13 @@ Function Export-Excel { } } if ($BoldTopRow) { - $range=$ws.Dimension.Address -replace $ws.Dimension.Rows, '1' + if ($Title) { + $range = $ws.Dimension.Address -replace '\d+', '2' + } + else { + $range = $ws.Dimension.Address -replace '\d+', '1' + } + $ws.Cells[$range].Style.Font.Bold = $true } if ($AutoSize) { @@ -687,7 +695,7 @@ Function Export-Excel { $rule.Style.Font.Color.Color = $targetConditionalText.ConditionalTextColor $rule.Style.Fill.PatternType = $targetConditionalText.PatternType $rule.Style.Fill.BackgroundColor.Color = $targetConditionalText.BackgroundColor - } + } } if ($CellStyleSB) {