Search in sources :

Example 1 with Row

use of org.xlsx4j.sml.Row 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 2 with Row

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

Example 3 with Row

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

the class XlsxRecordReader method readNextRow.

/**
 * Reads the next line from the buffer and converts to a string array.
 *
 * @return a string array with each comma-separated element as a separate
 *         entry.
 * @throws IOException if bad things happen during the read
 */
private List<String> readNextRow() {
    if (this.rowIndex < this.rows.size()) {
        final List<String> values = new ArrayList<>();
        final Row row = this.rows.get(this.rowIndex);
        final List<Cell> cells = row.getC();
        for (final Cell cell : cells) {
            String value = null;
            final String cellValue = cell.getV();
            final STCellType cellType = cell.getT();
            switch(cellType) {
                case S:
                    final int stringIndex = Integer.parseInt(cellValue);
                    final CTRst sharedString = this.sharedStringList.get(stringIndex);
                    final CTXstringWhitespace text = sharedString.getT();
                    value = text.getValue();
                    break;
                default:
                    if (cellValue == null) {
                        final CTRst is = cell.getIs();
                        if (is != null) {
                            value = is.getT().getValue();
                        }
                    } else {
                        value = cellValue;
                    }
                    break;
            }
            final int columnIndex = getColumnIndex(cell);
            if (columnIndex == -1) {
                values.add(value);
            } else {
                while (values.size() < columnIndex) {
                    values.add(null);
                }
                values.add(columnIndex, value);
            }
        }
        this.rowIndex++;
        return values;
    } else {
        throw new NoSuchElementException();
    }
}
Also used : STCellType(org.xlsx4j.sml.STCellType) CTRst(org.xlsx4j.sml.CTRst) ArrayList(java.util.ArrayList) Row(org.xlsx4j.sml.Row) Cell(org.xlsx4j.sml.Cell) NoSuchElementException(java.util.NoSuchElementException) CTXstringWhitespace(org.xlsx4j.sml.CTXstringWhitespace)

Example 4 with Row

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

the class XlsxRecordWriter method addHeaderRow.

private void addHeaderRow(final Worksheet worksheet, final RecordDefinition recordDefinition) {
    final List<Cols> columnGroups = worksheet.getCols();
    final Cols columns = smlObjectFactory.createCols();
    columnGroups.add(columns);
    final Row headerRow = smlObjectFactory.createRow();
    this.sheetRows.add(headerRow);
    final List<Cell> cells = headerRow.getC();
    for (final FieldDefinition field : recordDefinition.getFields()) {
        final String fieldName = field.getName();
        final Col column = smlObjectFactory.createCol();
        columns.getCol().add(column);
        column.setMin(field.getIndex() + 1);
        column.setMax(field.getIndex() + 1);
        column.setBestFit(true);
        final int textLength = Math.min(40, Math.max(fieldName.length() + 2, field.getMaxStringLength()));
        column.setWidth(textLength * 1.25);
        addCellInlineString(cells, fieldName);
    }
}
Also used : Col(org.xlsx4j.sml.Col) Cols(org.xlsx4j.sml.Cols) FieldDefinition(com.revolsys.record.schema.FieldDefinition) Row(org.xlsx4j.sml.Row) Cell(org.xlsx4j.sml.Cell)

Example 5 with Row

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

the class Xlsx4jNewSpreadSheet method addContent.

private static void addContent(WorksheetPart sheet) {
    // Minimal content already present
    SheetData sheetData = sheet.getJaxbElement().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);
}
Also used : SheetData(org.xlsx4j.sml.SheetData) Row(org.xlsx4j.sml.Row) Cell(org.xlsx4j.sml.Cell)

Aggregations

Cell (org.xlsx4j.sml.Cell)6 Row (org.xlsx4j.sml.Row)6 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 CTRst (org.xlsx4j.sml.CTRst)1 CTSheetFormatPr (org.xlsx4j.sml.CTSheetFormatPr)1 CTXstringWhitespace (org.xlsx4j.sml.CTXstringWhitespace)1 Col (org.xlsx4j.sml.Col)1 Cols (org.xlsx4j.sml.Cols)1 STCellType (org.xlsx4j.sml.STCellType)1