use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class BaseTestCellComment method readComments.
/**
* test that we can read cell comments from an existing workbook.
*/
@Test
public final void readComments() throws IOException {
Workbook wb = _testDataProvider.openSampleWorkbook("SimpleWithComments." + _testDataProvider.getStandardFileNameExtension());
Sheet sheet = wb.getSheetAt(0);
Cell cell;
Row row;
Comment comment;
for (int rownum = 0; rownum < 3; rownum++) {
row = sheet.getRow(rownum);
cell = row.getCell(0);
comment = cell.getCellComment();
assertNull("Cells in the first column are not commented", comment);
assertNull(sheet.getCellComment(new CellAddress(rownum, 0)));
}
for (int rownum = 0; rownum < 3; rownum++) {
row = sheet.getRow(rownum);
cell = row.getCell(1);
comment = cell.getCellComment();
assertNotNull("Cells in the second column have comments", comment);
assertNotNull("Cells in the second column have comments", sheet.getCellComment(new CellAddress(rownum, 1)));
assertEquals("Yegor Kozlov", comment.getAuthor());
assertFalse("cells in the second column have not empyy notes", "".equals(comment.getString().getString()));
assertEquals(rownum, comment.getRow());
assertEquals(cell.getColumnIndex(), comment.getColumn());
}
wb.close();
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class BaseTestCellComment method setAddress.
@Test
public void setAddress() {
Workbook wb = _testDataProvider.createWorkbook();
Sheet sh = wb.createSheet();
CreationHelper factory = wb.getCreationHelper();
Drawing<?> patriarch = sh.createDrawingPatriarch();
Comment comment = patriarch.createCellComment(factory.createClientAnchor());
assertEquals(CellAddress.A1, comment.getAddress());
CellAddress C2 = new CellAddress("C2");
assertEquals("C2", C2.formatAsString());
comment.setAddress(C2);
assertEquals(C2, comment.getAddress());
CellAddress E10 = new CellAddress(9, 4);
assertEquals("E10", E10.formatAsString());
comment.setAddress(9, 4);
assertEquals(E10, comment.getAddress());
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class CommentsTable method referenceUpdated.
/**
* Called after the reference is updated, so that
* we can reflect that in our cache
* @param oldReference the comment to remove from the commentRefs map
* @param comment the comment to replace in the commentRefs map
*/
public void referenceUpdated(CellAddress oldReference, CTComment comment) {
if (commentRefs != null) {
commentRefs.remove(oldReference);
commentRefs.put(new CellAddress(comment.getRef()), comment);
}
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class XSSFBHyperlinksTable method getHyperLinks.
/**
*
* @return a map of the hyperlinks. The key is the top left cell address in their CellRange
*/
public Map<CellAddress, List<XSSFHyperlinkRecord>> getHyperLinks() {
Map<CellAddress, List<XSSFHyperlinkRecord>> hyperlinkMap = new TreeMap<CellAddress, List<XSSFHyperlinkRecord>>(new TopLeftCellAddressComparator());
for (XSSFHyperlinkRecord hyperlinkRecord : hyperlinkRecords) {
CellAddress cellAddress = new CellAddress(hyperlinkRecord.getCellRangeAddress().getFirstRow(), hyperlinkRecord.getCellRangeAddress().getFirstColumn());
List<XSSFHyperlinkRecord> list = hyperlinkMap.get(cellAddress);
if (list == null) {
list = new ArrayList<XSSFHyperlinkRecord>();
}
list.add(hyperlinkRecord);
hyperlinkMap.put(cellAddress, list);
}
return hyperlinkMap;
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class XSSFDrawing method createCellComment.
/**
* Creates a comment.
* @param anchor the client anchor describes how this comment is attached
* to the sheet.
* @return the newly created comment.
*/
@Override
public XSSFComment createCellComment(ClientAnchor anchor) {
XSSFClientAnchor ca = (XSSFClientAnchor) anchor;
XSSFSheet sheet = getSheet();
//create comments and vmlDrawing parts if they don't exist
CommentsTable comments = sheet.getCommentsTable(true);
XSSFVMLDrawing vml = sheet.getVMLDrawing(true);
com.microsoft.schemas.vml.CTShape vmlShape = vml.newCommentShape();
if (ca.isSet()) {
// convert offsets from emus to pixels since we get a DrawingML-anchor
// but create a VML Drawing
int dx1Pixels = ca.getDx1() / Units.EMU_PER_PIXEL;
int dy1Pixels = ca.getDy1() / Units.EMU_PER_PIXEL;
int dx2Pixels = ca.getDx2() / Units.EMU_PER_PIXEL;
int dy2Pixels = ca.getDy2() / Units.EMU_PER_PIXEL;
String position = ca.getCol1() + ", " + dx1Pixels + ", " + ca.getRow1() + ", " + dy1Pixels + ", " + ca.getCol2() + ", " + dx2Pixels + ", " + ca.getRow2() + ", " + dy2Pixels;
vmlShape.getClientDataArray(0).setAnchorArray(0, position);
}
CellAddress ref = new CellAddress(ca.getRow1(), ca.getCol1());
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);
}
Aggregations