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();
}
}
Aggregations