diff options
author | PJ Fanning <fanningpj@apache.org> | 2022-03-09 20:12:37 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2022-03-09 20:12:37 +0000 |
commit | bdd7e65d855517245b8add708bbc99cda9934750 (patch) | |
tree | d4236a6d7a15c08e55d6509181400df8eea8da70 /poi-ooxml/src | |
parent | 552471e57873bf9a55ed8e694a3a41132fb4a9f4 (diff) | |
download | poi-bdd7e65d855517245b8add708bbc99cda9934750.tar.gz poi-bdd7e65d855517245b8add708bbc99cda9934750.zip |
[bug-65943] support rich text in SXSSFWorkbook (only when shared string table is enabled)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898803 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-ooxml/src')
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java | 90 |
1 files changed, 50 insertions, 40 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java index e1ff742684..089bbfb1b9 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java @@ -160,47 +160,12 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { @Test void useSharedStringsTableWithRichText() throws Exception { - try (SXSSFWorkbook wb = new SXSSFWorkbook(null, 10, false, true)) { - - SharedStringsTable sss = wb.getSharedStringSource(); - - assertNotNull(sss); - - XSSFFont redFont = new XSSFFont(); - redFont.setColor(new XSSFColor(new java.awt.Color(241,76,93), new DefaultIndexedColorMap())); - - Row row = wb.createSheet("S1").createRow(0); - - row.createCell(0).setCellValue("A"); - row.createCell(1).setCellValue("B"); - XSSFRichTextString rts = new XSSFRichTextString("A"); - rts.applyFont(redFont); - row.createCell(2).setCellValue(rts); - - try (XSSFWorkbook xssfWorkbook = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb)) { - sss = wb.getSharedStringSource(); - assertEquals(3, sss.getUniqueCount()); - assertTrue(wb.dispose()); + testUseSharedStringsTableWithRichText(false); + } - Sheet sheet1 = xssfWorkbook.getSheetAt(0); - assertEquals("S1", sheet1.getSheetName()); - assertEquals(1, sheet1.getPhysicalNumberOfRows()); - row = sheet1.getRow(0); - assertNotNull(row); - Cell cell = row.getCell(0); - assertNotNull(cell); - assertEquals("A", cell.getStringCellValue()); - cell = row.getCell(1); - assertNotNull(cell); - assertEquals("B", cell.getStringCellValue()); - cell = row.getCell(2); - assertNotNull(cell); - assertEquals("A", cell.getStringCellValue()); - XSSFRichTextString outputRichTextString = (XSSFRichTextString) cell.getRichStringCellValue(); - XSSFFont outputFont = outputRichTextString.getFontAtIndex(0); - assertEquals(redFont, outputFont); - } - } + @Test + void useSharedStringsTableWithRichTextAndCompression() throws Exception { + testUseSharedStringsTableWithRichText(true); } @Test @@ -569,4 +534,49 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook { @Disabled("not implemented") protected void changeSheetNameWithSharedFormulas() { } + + private void testUseSharedStringsTableWithRichText(boolean compressTempFiles) throws Exception { + try (SXSSFWorkbook wb = new SXSSFWorkbook(null, 10, compressTempFiles, true)) { + + SharedStringsTable sss = wb.getSharedStringSource(); + + assertNotNull(sss); + + XSSFFont redFont = new XSSFFont(); + redFont.setColor(new XSSFColor(new java.awt.Color(241,76,93), new DefaultIndexedColorMap())); + + Row row = wb.createSheet("S1").createRow(0); + + row.createCell(0).setCellValue("A"); + row.createCell(1).setCellValue("B"); + XSSFRichTextString rts = new XSSFRichTextString("A"); + rts.applyFont(redFont); + row.createCell(2).setCellValue(rts); + + try (XSSFWorkbook xssfWorkbook = SXSSFITestDataProvider.instance.writeOutAndReadBack(wb)) { + sss = wb.getSharedStringSource(); + assertEquals(3, sss.getUniqueCount()); + assertTrue(wb.dispose()); + + Sheet sheet1 = xssfWorkbook.getSheetAt(0); + assertEquals("S1", sheet1.getSheetName()); + assertEquals(1, sheet1.getPhysicalNumberOfRows()); + row = sheet1.getRow(0); + assertNotNull(row); + Cell cell = row.getCell(0); + assertNotNull(cell); + assertEquals("A", cell.getStringCellValue()); + cell = row.getCell(1); + assertNotNull(cell); + assertEquals("B", cell.getStringCellValue()); + cell = row.getCell(2); + assertNotNull(cell); + assertEquals("A", cell.getStringCellValue()); + XSSFRichTextString outputRichTextString = (XSSFRichTextString) cell.getRichStringCellValue(); + XSSFFont outputFont = outputRichTextString.getFontAtIndex(0); + assertEquals(redFont, outputFont); + } + } + } + } |