Fix Set-ExcelRange -Height changing the height of the row after the range - #1741
Fix Set-ExcelRange -Height changing the height of the row after the range#1741Mike-Crowley wants to merge 1 commit into
Conversation
…ange Set-ExcelRange -Height (and Set-ExcelRow -Height, which delegates to it) iterated one row past the end of the requested range: for a range starting at row N with R rows it looped N..(N+R), setting R+1 row heights. Subtract 1 so only the rows inside the range are changed, matching the -Width logic for columns. Adds regression tests covering Set-ExcelRow on a single row and Set-ExcelRange on a multi-row range, asserting neighbouring rows keep the default height, and imports the local module in the test file so it tests the repo code when run standalone. Fixes dfinke#1738 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Note on the failing Azure Pipelines checks: the failure is pre-existing pipeline infrastructure, not this change. Every job stops at
|
|
Hi @Mike-Crowley, you're a machine! Thanks for all the PRs and analysis, fantastic. Lots to chew on. It will take be a time to work through this and I have a lot on my plate. At a quick glance, I had been planning to turn off the Azure CI/CD. Had not taken the time to do so. I am going to kick off copilot on the PRs (thank you again for all of them), they look good so far. Then will proceed from there. Thank you - Doug |
There was a problem hiding this comment.
Pull request overview
Fixes an off-by-one error in Set-ExcelRange -Height that caused the row immediately after a targeted range to have its height modified as well (and could crash when the range ended at the worksheet’s last row). Adds a regression test context to ensure only the intended rows are affected.
Changes:
- Fix row-iteration bounds for
-Heightwhen applying to anExcelRange(stop at end row, not one past it). - Add Pester regression coverage for
Set-ExcelRow -HeightandSet-ExcelRange -Height, asserting neighboring rows retain the default height. - Ensure the modified test file imports the module directly when run standalone.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Public/Set-ExcelRange.ps1 | Corrects the height-setting loop to iterate only within the requested row range. |
| tests/Set-Row_Set-Column-SetFormat.tests.ps1 | Adds regression tests for Issue #1738 and imports the module for standalone test execution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Happy to help! As I recently mentioned in another issue, ImportExcel is my favorite open source PowerShell project and I wanted to use some of my Claude Fable budget to clear out a bit of the tech debt. |
|
That is great. So GitHub Copilot AI is reviewing Claude Fable work - love it Glad ImportExcel has helped out. I used GPT-5.x to work out addtions to ImportExcle to make it experiment making it "agentic". I have a local branch, when I publish it, I'll tag you. Good stuff! |
Fixes #1738
Problem
Set-ExcelRange -Height(andSet-ExcelRow -Height, which delegates to it) also changed the height of the first row after the requested range. From the issue's repro, setting row 1 to 42 and rows 4:5 to 32 produced:Cause
An off-by-one in the row loop in
Set-ExcelRange. EPPlus'sExcelRange.Rowsis a row count (End.Row - Start.Row + 1), soiterates one row past the end of the range (a 1-row range loops
N..N+1). The equivalent-Widthlogic for columns already subtracts 1, which is whySet-ExcelColumn -Widthwas unaffected.Fix
Subtract 1, matching the
-Widthbranch:The issue's repro now produces
42, 15, 15, 32, 32, 15, 15as expected. As a side effect this also fixes a crash when the range ends at the worksheet's last possible row (the old code called.Row(1048577), which throws).Tests
Added a regression context to
Set-Row_Set-Column-SetFormat.tests.ps1coveringSet-ExcelRowon a single row andSet-ExcelRangeon a multi-row range, asserting the neighbouring rows keep the default height. The new tests fail against the unfixed code ("Expected 15, but got 42") and pass with the fix. Also added the sameImport-Module $PSScriptRoot\..\ImportExcel.psd1 -Forceline used by sibling test files so this file tests the repo code when run standalone.Verified on Windows PowerShell 5.1 and PowerShell 7; full test file passes (22/22).
🤖 Generated with Claude Code