Search in sources :

Example 6 with Cell

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

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

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

Example 9 with Cell

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

the class Xlsx4jAddComments method createCell.

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 10 with Cell

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

the class Xlsx4jHeightAdjustment method main.

/**
 * @param args
 * @throws JAXBException
 * @throws Docx4JException
 */
public static void main(String[] args) throws JAXBException, Docx4JException {
    // The path to the documents directory.
    String dataDir = Utils.getDataDir(Xlsx4jHeightAdjustment.class);
    // TODO Auto-generated method stub
    SpreadsheetMLPackage pkg = SpreadsheetMLPackage.createPackage();
    WorksheetPart sheet = pkg.createWorksheetPart(new PartName("/xl/worksheets/sheet1.xml"), "Sheet1", 1);
    CTSheetFormatPr format = Context.getsmlObjectFactory().createCTSheetFormatPr();
    format.setDefaultRowHeight(5);
    format.setCustomHeight(Boolean.TRUE);
    sheet.getJaxbElement().setSheetFormatPr(format);
    SheetData sheetData = sheet.getJaxbElement().getSheetData();
    Row row = Context.getsmlObjectFactory().createRow();
    row.setHt(66.0);
    row.setCustomHeight(Boolean.TRUE);
    row.setR(1L);
    Cell cell1 = Context.getsmlObjectFactory().createCell();
    cell1.setV("1234");
    row.getC().add(cell1);
    Cell cell2 = Context.getsmlObjectFactory().createCell();
    cell2.setV("56");
    row.getC().add(cell2);
    sheetData.getRow().add(row);
    SaveToZipFile saver = new SaveToZipFile(pkg);
    saver.save(dataDir + "RowHeight-Xlsx4j.xlsx");
}
Also used : SpreadsheetMLPackage(org.docx4j.openpackaging.packages.SpreadsheetMLPackage) PartName(org.docx4j.openpackaging.parts.PartName) SheetData(org.xlsx4j.sml.SheetData) WorksheetPart(org.docx4j.openpackaging.parts.SpreadsheetML.WorksheetPart) SaveToZipFile(org.docx4j.openpackaging.io.SaveToZipFile) Row(org.xlsx4j.sml.Row) CTSheetFormatPr(org.xlsx4j.sml.CTSheetFormatPr) Cell(org.xlsx4j.sml.Cell)

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