Patch from hishidama to add Comment.getClientAnchor(). This closes #12 from github
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1636782 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3300ac2a56
commit
20438f4db5
@ -28,6 +28,7 @@ import org.apache.poi.hssf.record.NoteRecord;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -231,6 +232,17 @@ public class HSSFComment extends HSSFTextbox implements 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());
|
||||
|
@ -87,4 +87,10 @@ public interface Comment {
|
||||
*/
|
||||
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();
|
||||
}
|
@ -16,15 +16,17 @@
|
||||
==================================================================== */
|
||||
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 {
|
||||
|
||||
@ -172,6 +174,18 @@ 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
|
||||
*/
|
||||
|
@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel;
|
||||
|
||||
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;
|
||||
@ -167,4 +168,34 @@ public final class TestXSSFComment extends BaseTestCellComment {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package org.apache.poi.hssf.usermodel;
|
||||
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.
|
||||
@ -70,4 +71,34 @@ public final class TestHSSFComment extends BaseTestCellComment {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user