Skip to content

Commit

Permalink
Header formatting fix when Title is used (Issue dfinke#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brun authored and Brun committed Sep 20, 2017
1 parent 84ad629 commit a3c2a92
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions Export-Excel.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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%'
Expand Down Expand Up @@ -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'"

Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a3c2a92

Please sign in to comment.