final String entryName = zipArchiveEntry.getName();
PackagePartName ppn = null;
- try {
- // We get an error when we parse [Content_Types].xml
- // because it's not a valid URI.
- ppn = (CONTENT_TYPES_PART_NAME.equalsIgnoreCase(entryName)) ? null
- : PackagingURIHelper.createPartName(ZipHelper.getOPCNameFromZipItemName(entryName));
- } catch (Exception e) {
- // We assume we can continue, even in degraded mode ...
- LOG.atWarn().withThrowable(e).log("Entry {} is not valid, so this part won't be added to the package.", entryName);
+ // ignore trash parts
+ if (!entryName.startsWith("[trash]")) {
+ try {
+ // We get an error when we parse [Content_Types].xml
+ // because it's not a valid URI.
+ ppn = (CONTENT_TYPES_PART_NAME.equalsIgnoreCase(entryName)) ? null
+ : PackagingURIHelper.createPartName(ZipHelper.getOPCNameFromZipItemName(entryName));
+ } catch (Exception e) {
+ // We assume we can continue, even in degraded mode ...
+ LOG.atWarn().withThrowable(e).log("Entry {} is not valid, so this part won't be added to the package.", entryName);
+ }
}
this.partName = ppn;
}
}
+ @Test
+ void testIgnoreTrashParts() throws Exception {
+ try (XSSFWorkbook workbook = openSampleWorkbook("Excel_file_with_trash_item.xlsx")) {
+ for (PackagePart packagePart : workbook.getPackage().getParts()) {
+ assertFalse(packagePart.getPartName().toString().contains("trash"),
+ "should ignore part " + packagePart.getPartName());
+ }
+ }
+ }
+
private static void expectFormattedContent(Cell cell, String value) {
assertEquals(value, new DataFormatter().formatCellValue(cell),
"Cell " + ref(cell) + " has wrong formatted content.");