bug 52425: Error adding Comments into cloned Sheets; patch from Daniel

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1760221 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-09-11 04:05:42 +00:00
parent 72a9e2285b
commit a68e958a55
3 changed files with 49 additions and 3 deletions

View 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;

View 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);
}
}
}

Binary file not shown.