[bug-65120] PartAlreadyExistsException when creating cell comments (after some comments removed). Thanks to Raúl Wegmann

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886143 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-02-02 21:13:32 +00:00
parent 7a0cc6e7e5
commit d7eb8e949a
3 changed files with 29 additions and 3 deletions

View File

@ -160,6 +160,7 @@ subprojects {
exclude '**/BaseTestCellUtil.class'
exclude '**/TestUnfixedBugs.class'
exclude '**/TestOneFile.class'
include '**/TestXSSFSheet.class'
// Exclude Test Suites
exclude '**/All*Tests.class'

View File

@ -601,8 +601,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
CTLegacyDrawing ctDrawing = getCTLegacyDrawing();
if(ctDrawing == null) {
if(autoCreate) {
//drawingNumber = #drawings.size() + 1
int drawingNumber = getPackagePart().getPackage().getPartsByContentType(XSSFRelation.VML_DRAWINGS.getContentType()).size() + 1;
int drawingNumber = getNextPartNumber(XSSFRelation.VML_DRAWINGS,
getPackagePart().getPackage().getPartsByContentType(XSSFRelation.VML_DRAWINGS.getContentType()).size());
RelationPart rp = createRelationship(XSSFRelation.VML_DRAWINGS, XSSFFactory.getInstance(), drawingNumber, false);
drawing = rp.getDocumentPart();
String relId = rp.getRelationship().getId();

View File

@ -1887,7 +1887,7 @@ public final class TestXSSFSheet extends BaseTestXSheet {
*/
@Test
void testInsertCommentsToClonedSheet() throws IOException {
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("52425.xlsx")) {
try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("52425.xlsx")) {
CreationHelper helper = wb.getCreationHelper();
Sheet sheet2 = wb.createSheet("Sheet 2");
Sheet sheet3 = wb.cloneSheet(0);
@ -1995,4 +1995,29 @@ public final class TestXSSFSheet extends BaseTestXSheet {
}
}
}
@Test
public void bug65120() throws IOException {
XSSFWorkbook wb = new XSSFWorkbook();
CreationHelper creationHelper = wb.getCreationHelper();
Sheet sheet1 = wb.createSheet();
Cell cell1 = sheet1.createRow(0).createCell(0);
Comment comment1 = sheet1.createDrawingPatriarch().createCellComment(creationHelper.createClientAnchor());
cell1.setCellComment(comment1);
Sheet sheet2 = wb.createSheet();
Cell cell2 = sheet2.createRow(0).createCell(0);
Comment comment2 = sheet2.createDrawingPatriarch().createCellComment(creationHelper.createClientAnchor());
cell2.setCellComment(comment2);
wb.removeSheetAt(0);
Sheet sheet3 = wb.createSheet();
Cell cell3 = sheet3.createRow(0).createCell(0);
Comment comment3 = sheet3.createDrawingPatriarch().createCellComment(creationHelper.createClientAnchor());
cell3.setCellComment(comment3);
wb.close();
}
}