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:
parent
adfd0d7f6c
commit
abe46f40ed
@ -591,20 +591,21 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//search the referenced drawing in the list of the sheet's relations
|
//search the referenced drawing in the list of the sheet's relations
|
||||||
|
final String id = ctDrawing.getId();
|
||||||
for (RelationPart rp : getRelationParts()){
|
for (RelationPart rp : getRelationParts()){
|
||||||
POIXMLDocumentPart p = rp.getDocumentPart();
|
POIXMLDocumentPart p = rp.getDocumentPart();
|
||||||
if(p instanceof XSSFVMLDrawing) {
|
if(p instanceof XSSFVMLDrawing) {
|
||||||
XSSFVMLDrawing dr = (XSSFVMLDrawing)p;
|
XSSFVMLDrawing dr = (XSSFVMLDrawing)p;
|
||||||
String drId = rp.getRelationship().getId();
|
String drId = rp.getRelationship().getId();
|
||||||
if(drId.equals(ctDrawing.getId())){
|
if (drId.equals(id)) {
|
||||||
drawing = dr;
|
drawing = dr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
// do not break here since drawing has not been found yet (see bug 52425)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(drawing == null){
|
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;
|
return drawing;
|
||||||
|
@ -47,6 +47,9 @@ import org.apache.poi.ss.usermodel.Cell;
|
|||||||
import org.apache.poi.ss.usermodel.CellCopyPolicy;
|
import org.apache.poi.ss.usermodel.CellCopyPolicy;
|
||||||
import org.apache.poi.ss.usermodel.CellType;
|
import org.apache.poi.ss.usermodel.CellType;
|
||||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
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.FormulaError;
|
||||||
import org.apache.poi.ss.usermodel.IgnoredErrorType;
|
import org.apache.poi.ss.usermodel.IgnoredErrorType;
|
||||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||||
@ -1975,4 +1978,46 @@ public final class TestXSSFSheet extends BaseTestXSheet {
|
|||||||
wb.close();
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
test-data/spreadsheet/52425.xlsx
Normal file
BIN
test-data/spreadsheet/52425.xlsx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user