Search in sources :

Example 1 with Cell

use of org.xlsx4j.sml.Cell in project com.revolsys.open by revolsys.

the class XlsxRecordWriter method addCellNumber.

private void addCellNumber(final List<Cell> cells, final String value) {
    final Cell cell = smlObjectFactory.createCell();
    cell.setV(value);
    cells.add(cell);
}
Also used : Cell(org.xlsx4j.sml.Cell)

Example 2 with Cell

use of org.xlsx4j.sml.Cell in project com.revolsys.open by revolsys.

the class XlsxRecordWriter method addCellInlineString.

private void addCellInlineString(final List<Cell> cells, String value) {
    if (value == null) {
        value = "";
    }
    final CTXstringWhitespace cellContext = smlObjectFactory.createCTXstringWhitespace();
    cellContext.setValue(value);
    final CTRst cellString = new CTRst();
    cellString.setT(cellContext);
    final Cell cell = smlObjectFactory.createCell();
    cell.setT(STCellType.INLINE_STR);
    cell.setIs(cellString);
    cells.add(cell);
}
Also used : CTRst(org.xlsx4j.sml.CTRst) Cell(org.xlsx4j.sml.Cell) CTXstringWhitespace(org.xlsx4j.sml.CTXstringWhitespace)

Example 3 with Cell

use of org.xlsx4j.sml.Cell in project com.revolsys.open by revolsys.

the class XlsxRecordWriter method write.

@Override
public void write(final Record record) {
    final Row recordRow = smlObjectFactory.createRow();
    this.sheetRows.add(recordRow);
    final List<Cell> cells = recordRow.getC();
    for (final FieldDefinition field : this.recordDefinition.getFields()) {
        final Object value = record.getValue(field);
        final String string = field.toString(value);
        if (value instanceof Number) {
            addCellNumber(cells, string);
        } else {
            addCellInlineString(cells, string);
        }
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) Row(org.xlsx4j.sml.Row) Cell(org.xlsx4j.sml.Cell)

Example 4 with Cell

use of org.xlsx4j.sml.Cell in project Aspose.Cells-for-Java by aspose-cells.

the class Xlsx4jNewSpreadSheet method createCell.

/**
 *    // Note: if you are trying to add characters, not a number,
 *    // the easiest approach is to use inline strings (as opposed to the shared string table).
 *    // See http://openxmldeveloper.org/blog/b/openxmldeveloper/archive/2011/11/22/screen-cast-write-simpler-spreadsheetml-when-generating-spreadsheets.aspx
 *    // and http://www.docx4java.org/forums/xlsx-java-f15/cells-with-character-values-t874.html
 */
private static Cell createCell(String content) {
    Cell cell = Context.getsmlObjectFactory().createCell();
    CTXstringWhitespace ctx = Context.getsmlObjectFactory().createCTXstringWhitespace();
    ctx.setValue(content);
    CTRst ctrst = new CTRst();
    ctrst.setT(ctx);
    cell.setT(STCellType.INLINE_STR);
    // add ctrst as inline string
    cell.setIs(ctrst);
    return cell;
}
Also used : CTRst(org.xlsx4j.sml.CTRst) Cell(org.xlsx4j.sml.Cell) CTXstringWhitespace(org.xlsx4j.sml.CTXstringWhitespace)

Example 5 with Cell

use of org.xlsx4j.sml.Cell 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

Cell (org.xlsx4j.sml.Cell)10 Row (org.xlsx4j.sml.Row)6 CTRst (org.xlsx4j.sml.CTRst)4 CTXstringWhitespace (org.xlsx4j.sml.CTXstringWhitespace)4 SheetData (org.xlsx4j.sml.SheetData)3 FieldDefinition (com.revolsys.record.schema.FieldDefinition)2 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 SaveToZipFile (org.docx4j.openpackaging.io.SaveToZipFile)1 SpreadsheetMLPackage (org.docx4j.openpackaging.packages.SpreadsheetMLPackage)1 PartName (org.docx4j.openpackaging.parts.PartName)1 CommentsPart (org.docx4j.openpackaging.parts.SpreadsheetML.CommentsPart)1 WorksheetPart (org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart)1 VMLPart (org.docx4j.openpackaging.parts.VMLPart)1 Relationship (org.docx4j.relationships.Relationship)1 CTLegacyDrawing (org.xlsx4j.sml.CTLegacyDrawing)1 CTSheetFormatPr (org.xlsx4j.sml.CTSheetFormatPr)1 Col (org.xlsx4j.sml.Col)1 Cols (org.xlsx4j.sml.Cols)1 STCellType (org.xlsx4j.sml.STCellType)1