Search in sources :

Example 1 with CommentsPart

use of org.docx4j.openpackaging.parts.SpreadsheetML.CommentsPart in project Aspose.Cells-for-Java by aspose-cells.

the class Xlsx4jAddComments method addContent.

private static void addContent(WorksheetPart sheet) throws JAXBException, Docx4JException {
    // Minimal content already present
    SheetData sheetData = sheet.getContents().getSheetData();
    // Now add
    Row row = Context.getsmlObjectFactory().createRow();
    Cell cell = Context.getsmlObjectFactory().createCell();
    cell.setV("1234");
    row.getC().add(cell);
    row.getC().add(createCell("hello world!"));
    sheetData.getRow().add(row);
    // ADD A COMMENT TO CELL A1
    CommentsPart cp = new CommentsPart();
    cp.setContents(createComment("A1"));
    sheet.addTargetPart(cp);
    // Add <legacyDrawing r:id="rId1"/>
    VMLPart vmlPart = new VMLPart();
    // corresponds to A1
    vmlPart.setContents(getVml(0, 0));
    // you'll need extra VML for each comment
    Relationship rel = sheet.addTargetPart(vmlPart);
    CTLegacyDrawing legacyDrawing = Context.getsmlObjectFactory().createCTLegacyDrawing();
    legacyDrawing.setId(rel.getId());
    sheet.getContents().setLegacyDrawing(legacyDrawing);
}
Also used : SheetData(org.xlsx4j.sml.SheetData) CommentsPart(org.docx4j.openpackaging.parts.SpreadsheetML.CommentsPart) Relationship(org.docx4j.relationships.Relationship) VMLPart(org.docx4j.openpackaging.parts.VMLPart) Row(org.xlsx4j.sml.Row) Cell(org.xlsx4j.sml.Cell) CTLegacyDrawing(org.xlsx4j.sml.CTLegacyDrawing)

Aggregations

CommentsPart (org.docx4j.openpackaging.parts.SpreadsheetML.CommentsPart)1 VMLPart (org.docx4j.openpackaging.parts.VMLPart)1 Relationship (org.docx4j.relationships.Relationship)1 CTLegacyDrawing (org.xlsx4j.sml.CTLegacyDrawing)1 Cell (org.xlsx4j.sml.Cell)1 Row (org.xlsx4j.sml.Row)1 SheetData (org.xlsx4j.sml.SheetData)1