Skip to content

Set-ExcelRow -Height modifies the height of the next row as well #1738

Description

@szeder

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,C
1,2,3
4,5,6
7,8,9
10,11,12
13,14,15
16,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 ($r in 1..$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:
Image

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.

Activity

  1. 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
  2. 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
  3. self-assigned this
    on Mar 31, 2026
  4. dfinke commented on Mar 31, 2026

    @dfinke
    Owner

    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:

    1. Check the implementation of the -Height parameter in both Set-ExcelRow and Set-ExcelRange
    2. Verify the EPPlus API calls being made for setting row height
    3. 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.

    Thank you for the clear bug report!

  5. Mike-Crowley commented on Jul 29, 2026

    @Mike-Crowley

    Opened #1741 with a fix.

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions