]> source.dussan.org Git - poi.git/commitdiff
bug 52425: Error adding Comments into cloned Sheets; patch from Daniel
authorJaven O'Neal <onealj@apache.org>
Sun, 11 Sep 2016 04:05:42 +0000 (04:05 +0000)
committerJaven O'Neal <onealj@apache.org>
Sun, 11 Sep 2016 04:05:42 +0000 (04:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760221 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
test-data/spreadsheet/52425.xlsx [new file with mode: 0644]

index 5f1da12ecc6a18499513c75d3339e24dfc892b3a..98711c9dda36e44ec5be6dd68def513fe9807bcf 100644 (file)
@@ -591,20 +591,21 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
             }
         } else {
             //search the referenced drawing in the list of the sheet's relations
+            final String id = ctDrawing.getId();
             for (RelationPart rp : getRelationParts()){
                 POIXMLDocumentPart p = rp.getDocumentPart();
                 if(p instanceof XSSFVMLDrawing) {
                     XSSFVMLDrawing dr = (XSSFVMLDrawing)p;
                     String drId = rp.getRelationship().getId();
-                    if(drId.equals(ctDrawing.getId())){
+                    if (drId.equals(id)) {
                         drawing = dr;
                         break;
                     }
-                    break;
+                    // do not break here since drawing has not been found yet (see bug 52425)
                 }
             }
             if(drawing == null){
-                logger.log(POILogger.ERROR, "Can't find VML drawing with id=" + ctDrawing.getId() + " in the list of the sheet's relationships");
+                logger.log(POILogger.ERROR, "Can't find VML drawing with id=" + id + " in the list of the sheet's relationships");
             }
         }
         return drawing;
index 689e999bcbe9f82bd17eaffe08a643544be15f89..3f7be066d12360a1d89f9018c53af18d8167d82f 100644 (file)
@@ -47,6 +47,9 @@ import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellCopyPolicy;
 import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.ClientAnchor;
+import org.apache.poi.ss.usermodel.Comment;
+import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.ss.usermodel.Drawing;
 import org.apache.poi.ss.usermodel.FormulaError;
 import org.apache.poi.ss.usermodel.IgnoredErrorType;
 import org.apache.poi.ss.usermodel.IndexedColors;
@@ -1975,4 +1978,46 @@ public final class TestXSSFSheet extends BaseTestXSheet {
             wb.close();
         }
     }
+    
+    /**
+     * See bug #52425
+     */
+    @Test
+    public void testInsertCommentsToClonedSheet() {
+       Workbook wb = XSSFTestDataSamples.openSampleWorkbook("52425.xlsx");
+               CreationHelper helper = wb.getCreationHelper();
+               Sheet sheet2 = wb.createSheet("Sheet 2");
+               Sheet sheet3 = wb.cloneSheet(0);
+               wb.setSheetName(2, "Sheet 3");
+
+               // Adding Comment to new created Sheet 2
+               addComments(helper, sheet2);
+               // Adding Comment to cloned Sheet 3
+               addComments(helper, sheet3);
+       }
+    
+    private void addComments(CreationHelper helper, Sheet sheet) {
+               Drawing drawing = sheet.createDrawingPatriarch();
+
+               for (int i = 0; i < 2; i++) {
+                       ClientAnchor anchor = helper.createClientAnchor();
+                       anchor.setCol1(0);
+                       anchor.setRow1(0 + i);
+                       anchor.setCol2(2);
+                       anchor.setRow2(3 + i);
+
+                       Comment comment = drawing.createCellComment(anchor);
+                       comment.setString(helper.createRichTextString("BugTesting"));
+
+                       Row row = sheet.getRow(0 + i);
+                       if (row == null)
+                               row = sheet.createRow(0 + i);
+                       Cell cell = row.getCell(0);
+                       if (cell == null)
+                               cell = row.createCell(0);
+
+                       cell.setCellComment(comment);
+               }
+
+    }
 }
diff --git a/test-data/spreadsheet/52425.xlsx b/test-data/spreadsheet/52425.xlsx
new file mode 100644 (file)
index 0000000..0659822
Binary files /dev/null and b/test-data/spreadsheet/52425.xlsx differ