]> source.dussan.org Git - poi.git/commitdiff
[bug-65120] PartAlreadyExistsException when creating cell comments (after some commen...
authorPJ Fanning <fanningpj@apache.org>
Tue, 2 Feb 2021 21:13:32 +0000 (21:13 +0000)
committerPJ Fanning <fanningpj@apache.org>
Tue, 2 Feb 2021 21:13:32 +0000 (21:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886143 13f79535-47bb-0310-9956-ffa450edef68

build.gradle
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java

index 6a09be92d868b48623b8c98d427b34d5cd7e2725..95118a8129f469a3b7084bbab039427503860d22 100644 (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'
index b93f1658858bb44b24777d0975da51f316b1c2cf..cdc404b0289c4e29c8974a8d8a38ea05244003d7 100644 (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();
index 2071ca7962061e546bbfe538fc6b45bb547e1168..1ca51d3dcce6dacda9ceb4cb760bd9e189a1977e 100644 (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();
+    }
 }