import org.apache.poi.hssf.record.NoteStructureSubRecord;
import org.apache.poi.hssf.record.ObjRecord;
import org.apache.poi.hssf.record.TextObjectRecord;
+import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Comment;
/**
return true;
}
+ @Override
+ public ClientAnchor getClientAnchor() {
+ HSSFAnchor ha = super.getAnchor();
+ if (ha instanceof ClientAnchor) {
+ return (ClientAnchor) ha;
+ }
+
+ throw new IllegalStateException("Anchor can not be changed in "
+ + ClientAnchor.class.getSimpleName());
+ }
+
@Override
public void setShapeType(int shapeType) {
throw new IllegalStateException("Shape type can not be changed in "+this.getClass().getSimpleName());
*/
void setString(RichTextString string);
+ /**
+ * Return defines position of this anchor in the sheet.
+ *
+ * @return defines position of this anchor in the sheet
+ */
+ public ClientAnchor getClientAnchor();
}
\ No newline at end of file
==================================================================== */
package org.apache.poi.xssf.usermodel;
+import java.math.BigInteger;
+
+import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.model.CommentsTable;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
-import schemasMicrosoftComVml.CTShape;
-import java.math.BigInteger;
+import schemasMicrosoftComVml.CTShape;
public class XSSFComment implements Comment {
setString(new XSSFRichTextString(string));
}
+ @Override
+ public ClientAnchor getClientAnchor() {
+ String position = _vmlShape.getClientDataArray(0).getAnchorArray(0);
+ int[] pos = new int[8];
+ int i = 0;
+ for (String s : position.split(",")) {
+ pos[i++] = Integer.parseInt(s.trim());
+ }
+ XSSFClientAnchor ca = new XSSFClientAnchor(0, 0, 0, 0, pos[0], pos[2], pos[4], pos[6]);
+ return ca;
+ }
+
/**
* @return the xml bean holding this comment's properties
*/
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.ss.usermodel.BaseTestCellComment;
+import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.XSSFITestDataProvider;
assertEquals("", comment.getAuthor());
assertEquals(2, sheetComments.getNumberOfAuthors());
}
+
+ public void testGetClientAnchor() {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
+ XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ XSSFComment comment;
+ ClientAnchor anchor;
+
+ comment = drawing.createCellComment(new XSSFClientAnchor(101, 102, 103, 104, 1, 2, 3, 4));
+ anchor = comment.getClientAnchor();
+ assertEquals(0, anchor.getDx1());
+ assertEquals(0, anchor.getDy1());
+ assertEquals(0, anchor.getDx2());
+ assertEquals(0, anchor.getDy2());
+ assertEquals(1, anchor.getCol1());
+ assertEquals(2, anchor.getRow1());
+ assertEquals(3, anchor.getCol2());
+ assertEquals(4, anchor.getRow2());
+
+ comment = drawing.createCellComment(new XSSFClientAnchor());
+ anchor = comment.getClientAnchor();
+ assertEquals(0, anchor.getDx1());
+ assertEquals(0, anchor.getDy1());
+ assertEquals(0, anchor.getDx2());
+ assertEquals(0, anchor.getDy2());
+ assertEquals(1, anchor.getCol1());
+ assertEquals(0, anchor.getRow1());
+ assertEquals(3, anchor.getCol2());
+ assertEquals(3, anchor.getRow2());
+ }
}
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.usermodel.BaseTestCellComment;
+import org.apache.poi.ss.usermodel.ClientAnchor;
/**
* Tests TestHSSFCellComment.
comment = cell.getCellComment();
assertEquals("c6", comment.getString().getString());
}
+
+ public void testGetClientAnchor() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sheet = wb.createSheet();
+ HSSFPatriarch drawing = sheet.createDrawingPatriarch();
+ HSSFComment comment;
+ ClientAnchor anchor;
+
+ comment = drawing.createCellComment(new HSSFClientAnchor(101, 102, 103, 104, (short) 1, 2, (short) 3, 4));
+ anchor = comment.getClientAnchor();
+ assertEquals(101, anchor.getDx1());
+ assertEquals(102, anchor.getDy1());
+ assertEquals(103, anchor.getDx2());
+ assertEquals(104, anchor.getDy2());
+ assertEquals(1, anchor.getCol1());
+ assertEquals(2, anchor.getRow1());
+ assertEquals(3, anchor.getCol2());
+ assertEquals(4, anchor.getRow2());
+
+ comment = drawing.createCellComment(new HSSFClientAnchor());
+ anchor = comment.getClientAnchor();
+ assertEquals(0, anchor.getDx1());
+ assertEquals(0, anchor.getDy1());
+ assertEquals(0, anchor.getDx2());
+ assertEquals(0, anchor.getDy2());
+ assertEquals(0, anchor.getCol1());
+ assertEquals(0, anchor.getRow1());
+ assertEquals(0, anchor.getCol2());
+ assertEquals(0, anchor.getRow2());
+ }
}