@Override public void write(DataRow dataRow) { synchronized (syncObj) { // if( isClosed() ) // throw new IllegalStateException("is closed"); MetaData metaData = dataRow.getMetaData(); if (writeMetaData && !isMetaDataWrited(dataRow)) { writeMetaData(metaData); setMetaDataWrited(dataRow, true); moveToNextRow(); } Column[] columns = metaData.getColumns(); for (int colIdx = 0; colIdx < columns.length; colIdx++) { Object value = dataRow.get(colIdx); if (value == null) { writeNullCellValue( getCurrentRow(), colIdx, getHelper(getCurrentWorkbook()), null, columns[colIdx]); } else { writeCellValue( getCurrentRow(), colIdx, getHelper(getCurrentWorkbook()), null, value, columns[colIdx]); } } moveToNextRow(); } }
// <editor-fold defaultstate="collapsed" desc="writeMetaData"> protected void writeMetaData( Row row, int cellStart, CreationHelper createHelper, CellStyle cellStyle, MetaData meta) { int cellIdx = cellStart; for (Column column : meta.getColumns()) { String colName = column.getName(); if (colName == null) continue; Cell cell = row.getCell(cellIdx); if (cell == null) { cell = row.createCell(cellIdx); } cell.setCellValue(createHelper.createRichTextString(colName)); if (cellStyle != null) cell.setCellStyle(cellStyle); cellIdx++; } }