From 56b43139978d72c01af54b6398dc1083d39c90dc Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sun, 20 Mar 2022 21:41:31 +0000 Subject: [PATCH] [bug-64536] add getDimension on XSSFSheet git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1899091 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/usermodel/XSSFSheet.java | 14 ++++++++++ .../poi/xssf/usermodel/TestXSSFSheet.java | 24 ++++++++++++++++++ test-data/spreadsheet/1_NoIden.xlsx | Bin 0 -> 8038 bytes 3 files changed, 38 insertions(+) create mode 100644 test-data/spreadsheet/1_NoIden.xlsx diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 666ba1964d..a5aa37b7fe 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -3962,6 +3962,20 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx safeGetProtectionField().setSelectUnlockedCells(enabled); } + /** + * Reads the dimensions of the sheet data + * @return dimensions of the sheet data as a Cell Range (can be null) + * @since POI 5.2.3 + */ + public CellRangeAddress getDimension() { + CTSheetDimension ctSheetDimension = worksheet.getDimension(); + String ref = ctSheetDimension == null ? null : ctSheetDimension.getRef(); + if (ref != null) { + return CellRangeAddress.valueOf(ref); + } + return null; + } + private CTSheetProtection safeGetProtectionField() { if (!isSheetProtectionEnabled()) { return worksheet.addNewSheetProtection(); diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java index 08be04b107..269ca4622b 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFSheet.java @@ -2253,4 +2253,28 @@ public final class TestXSSFSheet extends BaseTestXSheet { assertTrue(row2.getZeroHeight()); } } + + @Test + void testBug64536() throws IOException { + try ( + XSSFWorkbook xssfWorkbook = (XSSFWorkbook) _testDataProvider.openSampleWorkbook("1_NoIden.xlsx"); + UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream() + ) { + XSSFSheet fileSheet = xssfWorkbook.getSheetAt(0); + assertEquals(CellRangeAddress.valueOf("B1:D9"), fileSheet.getDimension()); + + // Create Row and Cell, Then Set a Value + // 5, 2, 4 is just random number for test + Row fileRow = fileSheet.createRow(5); + Cell fileCell = fileRow.createCell(2, CellType.STRING); + fileCell.setCellValue("TEST VALUE"); + + xssfWorkbook.write(bos); + + try (XSSFWorkbook xssfWorkbook2 = new XSSFWorkbook(bos.toInputStream())) { + XSSFSheet xssfSheet = xssfWorkbook2.getSheetAt(0); + assertEquals(CellRangeAddress.valueOf("B1:F9"), xssfSheet.getDimension()); + } + } + } } diff --git a/test-data/spreadsheet/1_NoIden.xlsx b/test-data/spreadsheet/1_NoIden.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..a7f3159795106ce28c3a2b4c7d68567a2edd9c5c GIT binary patch literal 8038 zcma)h1yq#n);3+zp@hWH&Cn>)HFQZ2-QCR~A;^Gqr_v(Q-6;){(jg^C=ST=2_@4jh z=Q*G2-?Qd<=2>g@p1JQG*S)W;B9Dkf2#1D-2FIZ}rULhyJh=O8=wfc?%E5krEs5(; z>H=bh9zenwVN;7SxZ;YQVxT5Pt7oF11wI=B87S(;9yA6QlXE7}G;aBgh@N#_#G8-Y z1-p!l4W(pEK;lYvOgUkSeJy^Mc@2%LfU3>7{@e(igq)bf$Ej;El%1Y14u0&EPe9H2-Hv_6Xf{bd&&!0?-Gk!pNM?b2eLEmV3E9~m3&Ub z!(}lNoG-U6P7`a;1@=z_i4I_--)po0{_R7>F(156T;U`pn#Oya$E9rJ1MyqybCt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