out.close();
}
- public XSSFClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2,
+ @Override
+ public XSSFClientAnchor createAnchor(int dx1, int dy1, int dx2, int dy2,
int col1, int row1, int col2, int row2) {
return new XSSFClientAnchor(dx1, dy1, dx2, dy2, col1, row1, col2, row2);
}
return shape;
}
+ @Override
public XSSFPicture createPicture(ClientAnchor anchor, int pictureIndex){
return createPicture((XSSFClientAnchor)anchor, pictureIndex);
}
return chart;
}
- public XSSFChart createChart(ClientAnchor anchor) {
+ @Override
+ public XSSFChart createChart(ClientAnchor anchor) {
return createChart((XSSFClientAnchor)anchor);
}
* @param pictureIndex the index of the picture in the workbook collection of pictures,
* {@link org.apache.poi.xssf.usermodel.XSSFWorkbook#getAllPictures()} .
*/
+ @SuppressWarnings("resource")
protected PackageRelationship addPictureReference(int pictureIndex){
XSSFWorkbook wb = (XSSFWorkbook)getParent().getParent();
XSSFPictureData data = wb.getAllPictures().get(pictureIndex);
* to the sheet.
* @return the newly created comment.
*/
+ @Override
public XSSFComment createCellComment(ClientAnchor anchor) {
XSSFClientAnchor ca = (XSSFClientAnchor)anchor;
XSSFSheet sheet = (XSSFSheet)getParent();
vmlShape.getClientDataArray(0).setAnchorArray(0, position);
}
String ref = new CellReference(ca.getRow1(), ca.getCol1()).formatAsString();
- XSSFComment shape = new XSSFComment(comments, comments.newComment(ref), vmlShape);
- return shape;
+
+ if(comments.findCellComment(ref) != null) {
+ throw new IllegalArgumentException("Multiple cell comments in one cell are not allowed, cell: " + ref);
+ }
+
+ return new XSSFComment(comments, comments.newComment(ref), vmlShape);
}
/**
package org.apache.poi.xssf.usermodel;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.Function;
-import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
-import org.apache.poi.ss.usermodel.Cell;
-import org.apache.poi.ss.usermodel.CellStyle;
-import org.apache.poi.ss.usermodel.CellValue;
-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.DataFormatter;
-import org.apache.poi.ss.usermodel.DateUtil;
-import org.apache.poi.ss.usermodel.Drawing;
-import org.apache.poi.ss.usermodel.Font;
-import org.apache.poi.ss.usermodel.FormulaError;
-import org.apache.poi.ss.usermodel.FormulaEvaluator;
-import org.apache.poi.ss.usermodel.Hyperlink;
-import org.apache.poi.ss.usermodel.IndexedColors;
-import org.apache.poi.ss.usermodel.Name;
-import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.WorkbookFactory;
+import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
factory.createRichTextString("I like this cell. It's my favourite."));
comment1.setAuthor("Bob T. Fish");
+ anchor = factory.createClientAnchor();
+ anchor.setCol1(0);
+ anchor.setCol2(4);
+ anchor.setRow1(1);
+ anchor.setRow2(1);
Comment comment2 = drawing.createCellComment(anchor);
comment2.setString(
factory.createRichTextString("This is much less fun..."));
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.FontUnderline;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
* @author Yegor Kozlov
*/
public class TestXSSFDrawing extends TestCase {
- public void testRead(){
+ public void testRead() throws IOException{
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("WithDrawing.xlsx");
XSSFSheet sheet = wb.getSheetAt(0);
//the sheet has one relationship and it is XSSFDrawing
stream.close();
}*/
}
+
+ public void testBug56835CellComment() throws Exception {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ try {
+ XSSFSheet sheet = wb.createSheet();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+
+ // first comment works
+ ClientAnchor anchor = new XSSFClientAnchor(1, 1, 2, 2, 3, 3, 4, 4);
+ XSSFComment comment = drawing.createCellComment(anchor);
+ assertNotNull(comment);
+
+ try {
+ drawing.createCellComment(anchor);
+ fail("Should fail if we try to add the same comment for the same cell");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ } finally {
+ wb.close();
+ }
+ }
}