This is an automated email from the ASF dual-hosted git repository. centic9 pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/poi.git
commit 53015bc9ae5e6f41739c9288b91cb5ffb7dd4abd Author: Dominik Stadler <[email protected]> AuthorDate: Fri Aug 7 08:17:06 2026 +0200 Bug 70008: Fix inconsistent behavior when parsing whole column reference strings --- .../java/org/apache/poi/ss/util/AreaReference.java | 2 +- .../org/apache/poi/ss/util/TestAreaReference.java | 38 +++++++++++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/ss/util/AreaReference.java b/poi/src/main/java/org/apache/poi/ss/util/AreaReference.java index fd1cb4ff51..0c30199da6 100644 --- a/poi/src/main/java/org/apache/poi/ss/util/AreaReference.java +++ b/poi/src/main/java/org/apache/poi/ss/util/AreaReference.java @@ -83,7 +83,7 @@ public class AreaReference { int col1 = CellReference.convertColStringToIndex(part1); _firstCell = new CellReference(0, col0, true, firstIsAbs); - _lastCell = new CellReference(0xFFFF, col1, true, lastIsAbs); + _lastCell = new CellReference(_version.getLastRowIndex(), col1, true, lastIsAbs); _isSingleCell = false; // TODO - whole row refs } else { diff --git a/poi/src/test/java/org/apache/poi/ss/util/TestAreaReference.java b/poi/src/test/java/org/apache/poi/ss/util/TestAreaReference.java index 9f944e3918..8e649d42ed 100644 --- a/poi/src/test/java/org/apache/poi/ss/util/TestAreaReference.java +++ b/poi/src/test/java/org/apache/poi/ss/util/TestAreaReference.java @@ -20,6 +20,8 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.IOException; + import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.Sheet; @@ -69,18 +71,30 @@ class TestAreaReference { } @Test - void test62810() { - final Workbook wb = new HSSFWorkbook(); - final Sheet sheet = wb.createSheet("Ctor test"); - final String sheetName = sheet.getSheetName(); - final CellReference topLeft = new CellReference(sheetName, 1, 1, true, true); - final CellReference bottomRight = new CellReference(sheetName, 5, 10, true, true); - final AreaReference goodAreaRef = new AreaReference(topLeft, bottomRight, SpreadsheetVersion.EXCEL2007); - final AreaReference badAreaRef = new AreaReference(bottomRight, topLeft, SpreadsheetVersion.EXCEL2007); + void test62810() throws IOException { + try (final Workbook wb = new HSSFWorkbook()) { + final Sheet sheet = wb.createSheet("Ctor test"); + final String sheetName = sheet.getSheetName(); + final CellReference topLeft = new CellReference(sheetName, 1, 1, true, true); + final CellReference bottomRight = new CellReference(sheetName, 5, 10, true, true); + final AreaReference goodAreaRef = new AreaReference(topLeft, bottomRight, SpreadsheetVersion.EXCEL2007); + final AreaReference badAreaRef = new AreaReference(bottomRight, topLeft, SpreadsheetVersion.EXCEL2007); + + assertEquals("'Ctor test'!$B$2", topLeft.formatAsString()); + assertEquals("'Ctor test'!$K$6", bottomRight.formatAsString()); + assertEquals("'Ctor test'!$B$2:$K$6", goodAreaRef.formatAsString()); + assertEquals("'Ctor test'!$B$2:$K$6", badAreaRef.formatAsString()); + } + } - assertEquals("'Ctor test'!$B$2", topLeft.formatAsString()); - assertEquals("'Ctor test'!$K$6", bottomRight.formatAsString()); - assertEquals("'Ctor test'!$B$2:$K$6", goodAreaRef.formatAsString()); - assertEquals("'Ctor test'!$B$2:$K$6", badAreaRef.formatAsString()); + @Test + void test70008() { + AreaReference oldStyle = new AreaReference("A:B", SpreadsheetVersion.EXCEL97); + assertEquals(SpreadsheetVersion.EXCEL97.getLastRowIndex(), oldStyle.getLastCell().getRow()); + assertTrue(oldStyle.isWholeColumnReference()); + + AreaReference newStyle = new AreaReference("A:B", SpreadsheetVersion.EXCEL2007); + assertEquals(SpreadsheetVersion.EXCEL2007.getLastRowIndex(), newStyle.getLastCell().getRow()); + assertTrue(newStyle.isWholeColumnReference()); } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
