void writeSheet(Writer writer) throws WriterException {
        // create sheet
        this.sheet = workbook.createSheet(writer.sheetName());

        // setting styles
        CellStyle headerStyle = Constant.defaultHeaderStyle(workbook);
        CellStyle columnStyle = Constant.defaultColumnStyle(workbook);
        CellStyle titleStyle  = Constant.defaultTitleStyle(workbook);
        if (null != writer.titleStyle()) {
            titleStyle = writer.titleStyle().accept(workbook, titleStyle);
        }
        if (null != writer.headerStyle()) {
            headerStyle = writer.headerStyle().accept(workbook, headerStyle);
        }
        if (null != writer.cellStyle()) {
            columnStyle = writer.cellStyle().accept(workbook, columnStyle);
        }

        if (writer.isRaw()) {
            writer.sheetConsumer().accept(sheet);
        } else {
            // compute the Filed to be written
            Collection<?> rows   = writer.rows();
            Field[]       fields = rows.iterator().next().getClass().getDeclaredFields();

            this.fieldIndexes = new HashMap<>(fields.length);
            this.columns = new ArrayList<>();

            for (Field field : fields) {
                ExcelColumn column = field.getAnnotation(ExcelColumn.class);
                if (null != column) {
                    field.setAccessible(true);
                    fieldIndexes.put(column.index(), field);
                    columns.add(column);
                }
            }

            int colRowIndex = 0;
            // write title
            String title = writer.headerTitle();
            if (StringUtil.isNotEmpty(title)) {
                Integer maxColIndex = columns.stream()
                        .map(ExcelColumn::index)
                        .max(comparingInt(Integer::intValue))
                        .get();

                this.writeHeader(titleStyle, sheet, title, maxColIndex);
                colRowIndex = 1;
            }

            this.rowNum = writer.startRow();
            if (this.rowNum == 0) {
                this.rowNum = colRowIndex + 1;
            }

            try {
                // write column header
                this.writeColumnNames(colRowIndex, headerStyle);

                // write rows
                for (Object row : rows) {
                    this.writeRow(row, columnStyle);
                }
            } catch (Exception e) {
                log.error("write row fail", e);
            }
        }

        // write to OutputStream
        try (OutputStream os = outputStream) {
            workbook.write(os);
        } catch (Exception e) {
            throw new WriterException("workbook write to OutputStream error", e);
        }
    }
void writeSheet ( Writer writer ) throws WriterException { this . sheet = workbook . createSheet ( writer . sheetName ( ) ) ; CellStyle headerStyle = Constant . defaultHeaderStyle ( workbook ) ; CellStyle columnStyle = Constant . defaultColumnStyle ( workbook ) ; CellStyle titleStyle = Constant . defaultTitleStyle ( workbook ) ; if ( null != writer . titleStyle ( ) ) { titleStyle = writer . titleStyle ( ) . accept ( workbook , titleStyle ) ; } if ( null != writer . headerStyle ( ) ) { headerStyle = writer . headerStyle ( ) . accept ( workbook , headerStyle ) ; } if ( null != writer . cellStyle ( ) ) { columnStyle = writer . cellStyle ( ) . accept ( workbook , columnStyle ) ; } if ( writer . isRaw ( ) ) { writer . sheetConsumer ( ) . accept ( sheet ) ; } else { Collection < ? > rows = writer . rows ( ) ; Field [ ] fields = rows . iterator ( ) . next ( ) . getClass ( ) . getDeclaredFields ( ) ; this . fieldIndexes = new HashMap < > ( fields . length ) ; this . columns = new ArrayList < > ( ) ; for ( Field field : fields ) { ExcelColumn column = field . getAnnotation ( ExcelColumn . class ) ; if ( null != column ) { field . setAccessible ( true ) ; fieldIndexes . put ( column . index ( ) , field ) ; columns . add ( column ) ; } } int colRowIndex = 0 ; String title = writer . headerTitle ( ) ; if ( StringUtil . isNotEmpty ( title ) ) { Integer maxColIndex = columns . stream ( ) . map ( ExcelColumn :: index ) . max ( comparingInt ( Integer :: intValue ) ) . get ( ) ; this . writeHeader ( titleStyle , sheet , title , maxColIndex ) ; colRowIndex = 1 ; } this . rowNum = writer . startRow ( ) ; if ( this . rowNum == 0 ) { this . rowNum = colRowIndex + 1 ; } try { this . writeColumnNames ( colRowIndex , headerStyle ) ; for ( Object row : rows ) { this . writeRow ( row , columnStyle ) ; } } catch ( Exception e ) { log . error ( "write row fail" , e ) ; } } try ( OutputStream os = outputStream ) { workbook . write ( os ) ; } catch ( Exception e ) { throw new WriterException ( "workbook write to OutputStream error" , e ) ; } }
Write data to Excel Sheet
<p>
1. create sheet
2. write title(optional)
3. write column header
4. write row
5. write to OutputStream

@param writer excel-plus writer
@throws WriterException