removeRelation(getRelationById(toDelete.getKey()), true);
tables.remove(toDelete.getKey());
toDelete.getValue().onTableDelete();
- OPCPackage opcPackage = getWorkbook().getPackage();
- PackagePart packagePart = t.getPackagePart();
- if (packagePart != null && opcPackage.containPart(packagePart.getPartName())) {
- opcPackage.removePart(packagePart);
+ CTTableParts tblParts = worksheet.getTableParts();
+ int matchedPos = -1;
+ for (int i = 0; i < tblParts.sizeOfTablePartArray(); i++) {
+ if (toDelete.getKey().equals(tblParts.getTablePartArray(i).getId())) {
+ matchedPos = i;
+ break;
+ }
+ }
+ if (matchedPos != -1) {
+ tblParts.removeTablePart(matchedPos);
}
}
}
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
public final class TestXSSFTable {
assertEquals(cols.get(4).getName(), updatedCols.get(4).getName());
}
}
+
+ @Test
+ void bug66212() throws IOException {
+ try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("table-sample.xlsx")) {
+ XSSFTable table = wb.getTable("Tabelle1");
+ XSSFSheet sheet = table.getXSSFSheet();
+ assertEquals(1, sheet.getCTWorksheet().getTableParts().sizeOfTablePartArray());
+ sheet.removeTable(table);
+ assertEquals(0, sheet.getCTWorksheet().getTableParts().sizeOfTablePartArray());
+ }
+ }
}