From f12a414662702c56ccb6b3b4339465f71dcfe903 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Wed, 11 Dec 2019 20:07:01 +0000 Subject: [PATCH] [github-164] Fix Bug in XSSFTable.setCellReferences when table is single cell. Thanks to Travis Russell. This closes #164 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1871184 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/xssf/usermodel/XSSFTable.java | 2 +- .../org/apache/poi/xssf/usermodel/TestXSSFTable.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java index ab874c8bde..31b6e320cf 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java @@ -637,7 +637,7 @@ public class XSSFTable extends POIXMLDocumentPart implements Table { if (ref != null) { String[] boundaries = ref.split(":", 2); String from = boundaries[0]; - String to = boundaries[1]; + String to = boundaries.length == 2 ? boundaries[1] : boundaries[0]; startCellReference = new CellReference(from); endCellReference = new CellReference(to); } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java index 955e149101..733da646f9 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java @@ -215,6 +215,14 @@ public final class TestXSSFTable { } } + @Test + public void getEndCellReferenceFromSingleCellTable() throws IOException { + try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("SingleCellTable.xlsx")) { + XSSFTable table = wb.getTable("Table3"); + assertEquals(new CellReference("A2"), table.getEndCellReference()); + } + } + @Test public void getNumberOfMappedColumns() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx")) { -- 2.39.5