From 935c8ab06a6dd7921b0d48067339aa9603b5a848 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 15 Mar 2022 09:40:48 +0000 Subject: [PATCH] add xssf test (width/height) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898944 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/xssf/usermodel/XSSFSheet.java | 2 +- .../poi/xssf/usermodel/TestXSSFSheet.java | 30 +++++++++++++++++- test-data/spreadsheet/WidthsAndHeights.xlsx | Bin 0 -> 8597 bytes 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test-data/spreadsheet/WidthsAndHeights.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 8f13959b3b..513d9ad7ba 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 @@ -868,7 +868,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet, OoxmlSheetEx * Get the actual column width (in units of 1/256th of a character width ) * *

- * Note, the returned value is always gerater that {@link #getDefaultColumnWidth()} because the latter does not include margins. + * Note, the returned value is always greater that {@link #getDefaultColumnWidth()} because the latter does not include margins. * Actual column width measured as the number of characters of the maximum digit width of the * numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. There are 4 pixels of margin * padding (two on each side), plus 1 pixel padding for the gridlines. 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 4dc4d622ef..385d0af869 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 @@ -18,6 +18,7 @@ package org.apache.poi.xssf.usermodel; import static java.util.concurrent.TimeUnit.SECONDS; +import static org.apache.poi.xssf.XSSFTestDataSamples.openSamplePackage; import static org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook; import static org.apache.poi.xssf.XSSFTestDataSamples.writeOutAndReadBack; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -2190,7 +2191,7 @@ public final class TestXSSFSheet extends BaseTestXSheet { } @Test - public void bug65120() throws IOException { + void bug65120() throws IOException { try (XSSFWorkbook wb = new XSSFWorkbook()) { XSSFCreationHelper creationHelper = wb.getCreationHelper(); @@ -2222,4 +2223,31 @@ public final class TestXSSFSheet extends BaseTestXSheet { } } + @Test + void testCustomWidthAndHeight() throws IOException { + try (XSSFWorkbook wb = (XSSFWorkbook) _testDataProvider.openSampleWorkbook("WidthsAndHeights.xlsx")) { + XSSFSheet sheet = wb.getSheetAt(0); + assertEquals(5120, sheet.getColumnWidth(0)); + assertEquals(2048, sheet.getColumnWidth(1)); + assertEquals(0, sheet.getColumnWidth(2)); + assertEquals(140.034, sheet.getColumnWidthInPixels(0), 0.00001); + assertEquals(56.0136, sheet.getColumnWidthInPixels(1), 0.00001); + assertEquals(0.0, sheet.getColumnWidthInPixels(2), 0.00001); + assertFalse(sheet.isColumnHidden(0)); + assertFalse(sheet.isColumnHidden(1)); + assertTrue(sheet.isColumnHidden(2)); + XSSFRow row0 = sheet.getRow(0); + assertEquals(750, row0.getHeight()); + assertEquals(37.5, row0.getHeightInPoints(), 0.00001); + assertFalse(row0.getZeroHeight()); + XSSFRow row1 = sheet.getRow(1); + assertEquals(300, row1.getHeight()); + assertEquals(15.0, row1.getHeightInPoints(), 0.00001); + assertFalse(row1.getZeroHeight()); + XSSFRow row2 = sheet.getRow(2); + assertEquals(15, row2.getHeight()); + assertEquals(0.75, row2.getHeightInPoints(), 0.00001); + assertTrue(row2.getZeroHeight()); + } + } } diff --git a/test-data/spreadsheet/WidthsAndHeights.xlsx b/test-data/spreadsheet/WidthsAndHeights.xlsx new file mode 100644 index 0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