Search in sources :

Example 1 with MemoryPackagePart

use of org.apache.poi.openxml4j.opc.internal.MemoryPackagePart in project poi by apache.

the class TestXSSFWorkbook method bug51158a.

@Test
public void bug51158a() throws IOException {
    // create a workbook
    final XSSFWorkbook workbook = new XSSFWorkbook();
    try {
        workbook.createSheet("Test Sheet");
        XSSFSheet sheetBack = workbook.getSheetAt(0);
        // committing twice did add the XML twice without clearing the part in between
        sheetBack.commit();
        // ensure that a memory based package part does not have lingering data from previous commit() calls
        if (sheetBack.getPackagePart() instanceof MemoryPackagePart) {
            ((MemoryPackagePart) sheetBack.getPackagePart()).clear();
        }
        sheetBack.commit();
        String str = new String(IOUtils.toByteArray(sheetBack.getPackagePart().getInputStream()), "UTF-8");
        assertEquals(1, countMatches(str, "<worksheet"));
    } finally {
        workbook.close();
    }
}
Also used : MemoryPackagePart(org.apache.poi.openxml4j.opc.internal.MemoryPackagePart) RichTextString(org.apache.poi.ss.usermodel.RichTextString) Test(org.junit.Test)

Aggregations

MemoryPackagePart (org.apache.poi.openxml4j.opc.internal.MemoryPackagePart)1 RichTextString (org.apache.poi.ss.usermodel.RichTextString)1 Test (org.junit.Test)1