add xssf test (width/height)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898944 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2022-03-15 09:40:48 +00:00
parent f19233164c
commit 935c8ab06a
3 changed files with 30 additions and 2 deletions

View File

@ -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 ) * Get the actual column width (in units of 1/256th of a character width )
* *
* <p> * <p>
* 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 * 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 * 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. * padding (two on each side), plus 1 pixel padding for the gridlines.

View File

@ -18,6 +18,7 @@
package org.apache.poi.xssf.usermodel; package org.apache.poi.xssf.usermodel;
import static java.util.concurrent.TimeUnit.SECONDS; 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.openSampleWorkbook;
import static org.apache.poi.xssf.XSSFTestDataSamples.writeOutAndReadBack; import static org.apache.poi.xssf.XSSFTestDataSamples.writeOutAndReadBack;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@ -2190,7 +2191,7 @@ public final class TestXSSFSheet extends BaseTestXSheet {
} }
@Test @Test
public void bug65120() throws IOException { void bug65120() throws IOException {
try (XSSFWorkbook wb = new XSSFWorkbook()) { try (XSSFWorkbook wb = new XSSFWorkbook()) {
XSSFCreationHelper creationHelper = wb.getCreationHelper(); 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());
}
}
} }

Binary file not shown.