You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Set-ExcelRow -Height modifies the height of the next row as well #1738
When using Set-ExcelRow or Set-ExcelRange to set the height of a row, the height of the next row is modified as well.
Steps to reproduce the issue:
$Data=ConvertFrom-Csv@"A,B,C1,2,34,5,67,8,910,11,1213,14,1516,17,18"@$XlPkg=$Data|Export-Excel-WorksheetName TestHeight -TableStyle None -PassThru
Set-ExcelRow-Worksheet $XlPkg.TestHeight-Row 1-Height 42-WrapText -VerticalAlignment Top -HorizontalAlignment Center -Bold -Italic -Underline
Set-ExcelRange-Worksheet $XlPkg.TestHeight-Range '4:5'-Height 32-WrapText -VerticalAlignment Top -HorizontalAlignment Center -Bold -Italic -Underline
foreach ($rin1..$XlPkg.TestHeight.Dimension.Rows) { $XlPkg.TestHeight.Row($r).Height }
The output of the loop in the last line is:
42
42
15
32
32
32
15
The resulting Excel file looks like this:
I would have expected that only the height of row 1 is set to 42, and only the height of rows 4 and 5 are set to 32, while the height of the other rows remains unchanged (i.e. the default 15).
What happens instead is that the height of rows 1 and 2 are set to 42, and the height of rows 4, 5 and 6 are set to 32.
Setting all those other formating properties is not necessary to trigger this issue. I've only specified those options to demonstrate that they seem to behave as expected, i.e. they affect only the given rows. Only the -Height "overflows" into the next row. Set-ExcelColumn -Width seems to be working as expected as well.
changed the title [-]Set-ExcelRow -Heigh` modifies the height of the next row as well[/-][+]Set-ExcelRow -Heigh modifies the height of the next row as well[/+]on Mar 24, 2026
changed the title [-]Set-ExcelRow -Heigh modifies the height of the next row as well[/-][+]Set-ExcelRow -Height modifies the height of the next row as well[/+]on Mar 31, 2026
Thank you for reporting this issue with detailed reproduction steps! This is indeed a bug in the Set-ExcelRow and Set-ExcelRange functions where the -Height parameter affects the next row as well.
Based on your description and test case, it appears that when setting the height for row N, row N+1 is also being modified. This is clearly not the intended behavior, especially since other formatting properties (Bold, Italic, Underline, alignment, etc.) are correctly applied only to the specified rows.
The issue seems to be specific to the -Height parameter, as you noted that Set-ExcelColumn -Width works correctly.
This could be related to how the row height is being set in the underlying EPPlus library. A potential cause might be:
An off-by-one error in the row indexing when applying height
The row range being incorrectly calculated or expanded
Incorrect iteration logic that processes one extra row
To help diagnose this further, it would be helpful to:
Check the implementation of the -Height parameter in both Set-ExcelRow and Set-ExcelRange
Verify the EPPlus API calls being made for setting row height
Ensure the row range is properly bounded
I'll investigate the source code to identify the root cause. In the meantime, as a workaround, you might try setting the height of the previous row back to the default value explicitly after using Set-ExcelRow, though this is clearly not ideal.
Root cause: an off-by-one in the row-height loop in Set-ExcelRange. EPPlus's ExcelRange.Rows is a row count, so ($Range.Start.Row)..($Range.Start.Row + $Range.Rows) iterated one row past the end of the range — which is why a 1-row Set-ExcelRow touched two rows. The -Width branch already subtracted 1, which is why Set-ExcelColumn -Width behaved correctly.
With the fix, the repro above produces 42, 15, 15, 32, 32, 15, 15 as expected (verified on PowerShell 5.1 and 7), and a regression test is included.
Activity
[-]Set-ExcelRow -Heigh` modifies the height of the next row as well[/-][+]Set-ExcelRow -Heigh modifies the height of the next row as well[/+][-]Set-ExcelRow -Heigh modifies the height of the next row as well[/-][+]Set-ExcelRow -Height modifies the height of the next row as well[/+]dfinke commentedon Mar 31, 2026
Thank you for reporting this issue with detailed reproduction steps! This is indeed a bug in the Set-ExcelRow and Set-ExcelRange functions where the -Height parameter affects the next row as well.
Based on your description and test case, it appears that when setting the height for row N, row N+1 is also being modified. This is clearly not the intended behavior, especially since other formatting properties (Bold, Italic, Underline, alignment, etc.) are correctly applied only to the specified rows.
The issue seems to be specific to the -Height parameter, as you noted that Set-ExcelColumn -Width works correctly.
This could be related to how the row height is being set in the underlying EPPlus library. A potential cause might be:
To help diagnose this further, it would be helpful to:
I'll investigate the source code to identify the root cause. In the meantime, as a workaround, you might try setting the height of the previous row back to the default value explicitly after using Set-ExcelRow, though this is clearly not ideal.
Thank you for the clear bug report!
Mike-Crowley commentedon Jul 29, 2026
Opened #1741 with a fix.
Root cause: an off-by-one in the row-height loop in
Set-ExcelRange. EPPlus'sExcelRange.Rowsis a row count, so($Range.Start.Row)..($Range.Start.Row + $Range.Rows)iterated one row past the end of the range — which is why a 1-rowSet-ExcelRowtouched two rows. The-Widthbranch already subtracted 1, which is whySet-ExcelColumn -Widthbehaved correctly.With the fix, the repro above produces
42, 15, 15, 32, 32, 15, 15as expected (verified on PowerShell 5.1 and 7), and a regression test is included.