use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class XSSFCell method removeCellComment.
/**
* Removes the comment for this cell, if there is one.
*/
@Override
public void removeCellComment() {
XSSFComment comment = getCellComment();
if (comment != null) {
CellAddress ref = new CellAddress(getReference());
XSSFSheet sh = getSheet();
sh.getCommentsTable(false).removeComment(ref);
sh.getVMLDrawing(false).removeCommentShape(getRowIndex(), getColumnIndex());
}
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class XSSFBCommentsTable method handleRecord.
@Override
public void handleRecord(int id, byte[] data) throws XSSFBParseException {
XSSFBRecordType recordType = XSSFBRecordType.lookup(id);
switch(recordType) {
case BrtBeginComment:
int offset = 0;
authorId = XSSFBUtils.castToInt(LittleEndian.getUInt(data));
offset += LittleEndian.INT_SIZE;
cellRange = XSSFBCellRange.parse(data, offset, cellRange);
offset += XSSFBCellRange.length;
//for strict parsing; confirm that firstRow==lastRow and firstCol==colLats (2.4.28)
cellAddress = new CellAddress(cellRange.firstRow, cellRange.firstCol);
break;
case BrtCommentText:
XSSFBRichStr xssfbRichStr = XSSFBRichStr.build(data, 0);
comment = xssfbRichStr.getString();
break;
case BrtEndComment:
comments.put(cellAddress, new XSSFBComment(cellAddress, authors.get(authorId), comment));
authorId = -1;
cellAddress = null;
break;
case BrtCommentAuthor:
authorBuffer.setLength(0);
XSSFBUtils.readXLWideString(data, 0, authorBuffer);
authors.add(authorBuffer.toString());
break;
}
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class XSSFBSheetHandler method handleCellValue.
private void handleCellValue(String formattedValue) {
CellAddress cellAddress = new CellAddress(currentRow, cellBuffer.getColNum());
XSSFBComment comment = null;
if (comments != null) {
comment = comments.get(cellAddress);
}
handler.cell(cellAddress.formatAsString(), formattedValue, comment);
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class TestXSSFComment method bug57838DeleteRowsWthCommentsBug.
@Test
public void bug57838DeleteRowsWthCommentsBug() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57838.xlsx");
Sheet sheet = wb.getSheetAt(0);
Comment comment1 = sheet.getCellComment(new CellAddress(2, 1));
assertNotNull(comment1);
Comment comment2 = sheet.getCellComment(new CellAddress(2, 2));
assertNotNull(comment2);
Row row = sheet.getRow(2);
assertNotNull(row);
// Remove row from index 2
sheet.removeRow(row);
row = sheet.getRow(2);
// Row is null since we deleted it.
assertNull(row);
comment1 = sheet.getCellComment(new CellAddress(2, 1));
// comment should be null but will fail due to bug
assertNull(comment1);
comment2 = sheet.getCellComment(new CellAddress(2, 2));
// comment should be null but will fail due to bug
assertNull(comment2);
wb.close();
}
use of org.apache.poi.ss.util.CellAddress in project poi by apache.
the class TestXSSFComment method testBug58175.
@Test
public void testBug58175() throws IOException {
Workbook wb = new SXSSFWorkbook();
try {
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(1);
Cell cell = row.createCell(3);
cell.setCellValue("F4");
CreationHelper factory = wb.getCreationHelper();
// When the comment box is visible, have it show in a 1x3 space
ClientAnchor anchor = factory.createClientAnchor();
anchor.setCol1(cell.getColumnIndex());
anchor.setCol2(cell.getColumnIndex() + 1);
anchor.setRow1(row.getRowNum());
anchor.setRow2(row.getRowNum() + 3);
XSSFClientAnchor ca = (XSSFClientAnchor) anchor;
// create comments and vmlDrawing parts if they don't exist
CommentsTable comments = ((SXSSFWorkbook) wb).getXSSFWorkbook().getSheetAt(0).getCommentsTable(true);
XSSFVMLDrawing vml = ((SXSSFWorkbook) wb).getXSSFWorkbook().getSheetAt(0).getVMLDrawing(true);
CTShape vmlShape1 = vml.newCommentShape();
if (ca.isSet()) {
String position = ca.getCol1() + ", 0, " + ca.getRow1() + ", 0, " + ca.getCol2() + ", 0, " + ca.getRow2() + ", 0";
vmlShape1.getClientDataArray(0).setAnchorArray(0, position);
}
// create the comment in two different ways and verify that there is no difference
XSSFComment shape1 = new XSSFComment(comments, comments.newComment(CellAddress.A1), vmlShape1);
shape1.setColumn(ca.getCol1());
shape1.setRow(ca.getRow1());
CTShape vmlShape2 = vml.newCommentShape();
if (ca.isSet()) {
String position = ca.getCol1() + ", 0, " + ca.getRow1() + ", 0, " + ca.getCol2() + ", 0, " + ca.getRow2() + ", 0";
vmlShape2.getClientDataArray(0).setAnchorArray(0, position);
}
CellAddress ref = new CellAddress(ca.getRow1(), ca.getCol1());
XSSFComment shape2 = new XSSFComment(comments, comments.newComment(ref), vmlShape2);
assertEquals(shape1.getAuthor(), shape2.getAuthor());
assertEquals(shape1.getClientAnchor(), shape2.getClientAnchor());
assertEquals(shape1.getColumn(), shape2.getColumn());
assertEquals(shape1.getRow(), shape2.getRow());
assertEquals(shape1.getCTComment().toString(), shape2.getCTComment().toString());
assertEquals(shape1.getCTComment().getRef(), shape2.getCTComment().getRef());
/*CommentsTable table1 = shape1.getCommentsTable();
CommentsTable table2 = shape2.getCommentsTable();
assertEquals(table1.getCTComments().toString(), table2.getCTComments().toString());
assertEquals(table1.getNumberOfComments(), table2.getNumberOfComments());
assertEquals(table1.getRelations(), table2.getRelations());*/
assertEquals("The vmlShapes should have equal content afterwards", vmlShape1.toString().replaceAll("_x0000_s\\d+", "_x0000_s0000"), vmlShape2.toString().replaceAll("_x0000_s\\d+", "_x0000_s0000"));
} finally {
wb.close();
}
}
Aggregations