Search in sources :

Example 1 with STCellType

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

Aggregations

ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 CTRst (org.xlsx4j.sml.CTRst)1 CTXstringWhitespace (org.xlsx4j.sml.CTXstringWhitespace)1 Cell (org.xlsx4j.sml.Cell)1 Row (org.xlsx4j.sml.Row)1 STCellType (org.xlsx4j.sml.STCellType)1