use of org.apache.poi.xssf.model.CommentsTable 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();
}
}
use of org.apache.poi.xssf.model.CommentsTable in project poi by apache.
the class TestXSSFComment method constructor.
/**
* test properties of a newly constructed comment
*/
@Test
public void constructor() {
CommentsTable sheetComments = new CommentsTable();
assertNotNull(sheetComments.getCTComments().getCommentList());
assertNotNull(sheetComments.getCTComments().getAuthors());
assertEquals(1, sheetComments.getCTComments().getAuthors().sizeOfAuthorArray());
assertEquals(1, sheetComments.getNumberOfAuthors());
CTComment ctComment = sheetComments.newComment(CellAddress.A1);
CTShape vmlShape = CTShape.Factory.newInstance();
XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);
assertEquals(null, comment.getString());
assertEquals(0, comment.getRow());
assertEquals(0, comment.getColumn());
assertEquals("", comment.getAuthor());
assertEquals(false, comment.isVisible());
}
use of org.apache.poi.xssf.model.CommentsTable in project poi by apache.
the class TestXSSFComment method getSetCol.
@Test
public void getSetCol() {
CommentsTable sheetComments = new CommentsTable();
XSSFVMLDrawing vml = new XSSFVMLDrawing();
CTComment ctComment = sheetComments.newComment(CellAddress.A1);
CTShape vmlShape = vml.newCommentShape();
XSSFComment comment = new XSSFComment(sheetComments, ctComment, vmlShape);
comment.setColumn(1);
assertEquals(1, comment.getColumn());
assertEquals(1, new CellReference(ctComment.getRef()).getCol());
assertEquals(1, vmlShape.getClientDataArray(0).getColumnArray(0).intValue());
comment.setColumn(5);
assertEquals(5, comment.getColumn());
assertEquals(5, new CellReference(ctComment.getRef()).getCol());
assertEquals(5, vmlShape.getClientDataArray(0).getColumnArray(0).intValue());
}
use of org.apache.poi.xssf.model.CommentsTable in project poi by apache.
the class TestXSSFSheet method commentsTable.
@Test
public void commentsTable() throws IOException {
XSSFWorkbook wb1 = new XSSFWorkbook();
XSSFSheet sheet1 = wb1.createSheet();
CommentsTable comment1 = sheet1.getCommentsTable(false);
assertNull(comment1);
comment1 = sheet1.getCommentsTable(true);
assertNotNull(comment1);
assertEquals("/xl/comments1.xml", comment1.getPackagePart().getPartName().getName());
assertSame(comment1, sheet1.getCommentsTable(true));
//second sheet
XSSFSheet sheet2 = wb1.createSheet();
CommentsTable comment2 = sheet2.getCommentsTable(false);
assertNull(comment2);
comment2 = sheet2.getCommentsTable(true);
assertNotNull(comment2);
assertSame(comment2, sheet2.getCommentsTable(true));
assertEquals("/xl/comments2.xml", comment2.getPackagePart().getPartName().getName());
//comment1 and comment2 are different objects
assertNotSame(comment1, comment2);
wb1.close();
//now test against a workbook containing cell comments
XSSFWorkbook wb2 = XSSFTestDataSamples.openSampleWorkbook("WithMoreVariousData.xlsx");
sheet1 = wb2.getSheetAt(0);
comment1 = sheet1.getCommentsTable(true);
assertNotNull(comment1);
assertEquals("/xl/comments1.xml", comment1.getPackagePart().getPartName().getName());
assertSame(comment1, sheet1.getCommentsTable(true));
wb2.close();
}
use of org.apache.poi.xssf.model.CommentsTable in project poi by apache.
the class XSSFSheet method read.
protected void read(InputStream is) throws IOException {
try {
worksheet = WorksheetDocument.Factory.parse(is, DEFAULT_XML_OPTIONS).getWorksheet();
} catch (XmlException e) {
throw new POIXMLException(e);
}
initRows(worksheet);
columnHelper = new ColumnHelper(worksheet);
// Look for bits we're interested in
for (RelationPart rp : getRelationParts()) {
POIXMLDocumentPart p = rp.getDocumentPart();
if (p instanceof CommentsTable) {
sheetComments = (CommentsTable) p;
}
if (p instanceof XSSFTable) {
tables.put(rp.getRelationship().getId(), (XSSFTable) p);
}
if (p instanceof XSSFPivotTable) {
getWorkbook().getPivotTables().add((XSSFPivotTable) p);
}
}
// Process external hyperlinks for the sheet, if there are any
initHyperlinks();
}
Aggregations