src/main/java/org/braisdom/excel/WorkbookTemplate.java
public void process(TemplateDataSource templateDataSource,
                        WorkbookWriter workbookWriter,
                        File excelFile) throws IOException, DocumentException {
        String templateContent = processTemplate(templateDataSource);
        Document document = DocumentHelper.parseText(templateContent);
        List<Element> sheetElements = document.getRootElement().elements(WorkbookElement.SHEET.getValue());

        for (Element sheetElement : sheetElements) {
            SheetWriter sheetWriter = workbookWriter.createSheetWriter();
            List<Element> rowElements = sheetElement.elements();
            int realRowIndex = 0;

            processSheet(sheetElement, sheetWriter);

            for (int rowIndex = 0; rowIndex < rowElements.size(); rowIndex++) {
                Element rowElement = rowElements.get(rowIndex);
                int assignedRowGaps = StyleUtils.safeInteger(rowElement.attributeValue(WorkbookAttribute.ROW_GAPS.getValue()));
                // The gaps defined of row will be effecting the realRowIndex.
                realRowIndex += assignedRowGaps;
                if (rowElement.getName().equals(WorkbookElement.ROW.getValue())) {
                    processRowElement(realRowIndex + rowIndex, rowElement, sheetWriter);
                } else if (rowElement.getName().equals(WorkbookElement.DATA_TABLE.getValue())) {
                    // The DataTable has multiple rows, so the realRowIndex will be changed after it generated.
                    realRowIndex = processDataTableElement(realRowIndex, rowElement, sheetWriter);
                }
            }
        }
        workbookWriter.setActiveSheet(0);
        workbookWriter.save(new FileOutputStream(excelFile));
    }
/**
     * The main method for Excel file generating.
     *
     * @param templateDataSource the data source will be used for thymeleaf
     * @param workbookWriter     The Excel file generator.
     * @param excelFile          The Excel file reference.
     * @throws IOException       If read template source failure.
     * @throws DocumentException If parsing template content failure
     */
The main method for Excel file generating.
@param templateDataSource the data source will be used for thymeleaf
@param workbookWriter     The Excel file generator.
@param excelFile          The Excel file reference.
@throws IOException       If read template source failure.
@throws DocumentException If parsing template content failure
The main method for Excel file generating . @param templateDataSource the data source will be used for thymeleaf @param workbookWriter The Excel file generator . @param excelFile The Excel file reference . @throws IOException If read template source failure . @throws DocumentException If parsing template content failure
public void process(TemplateDataSource templateDataSource,
                        WorkbookWriter workbookWriter,
                        File excelFile) throws IOException, DocumentException {
        String templateContent = processTemplate(templateDataSource);
        Document document = DocumentHelper.parseText(templateContent);
        List<Element> sheetElements = document.getRootElement().elements(WorkbookElement.SHEET.getValue());
        for (Element sheetElement : sheetElements) {
            SheetWriter sheetWriter = workbookWriter.createSheetWriter();
            List<Element> rowElements = sheetElement.elements();
            int realRowIndex = 0;
            processSheet(sheetElement, sheetWriter);
            for (int rowIndex = 0; rowIndex < rowElements.size(); rowIndex++) {
                Element rowElement = rowElements.get(rowIndex);
                int assignedRowGaps = StyleUtils.safeInteger(rowElement.attributeValue(WorkbookAttribute.ROW_GAPS.getValue()));
                realRowIndex += assignedRowGaps;
                if (rowElement.getName().equals(WorkbookElement.ROW.getValue())) {
                    processRowElement(realRowIndex + rowIndex, rowElement, sheetWriter);
                } else if (rowElement.getName().equals(WorkbookElement.DATA_TABLE.getValue())) {
                    realRowIndex = processDataTableElement(realRowIndex, rowElement, sheetWriter);
                }
            }
        }
        workbookWriter.setActiveSheet(0);
        workbookWriter.save(new FileOutputStream(excelFile));
    }
public void process ( TemplateDataSource templateDataSource , WorkbookWriter workbookWriter , File excelFile ) throws IOException , DocumentException { String templateContent = processTemplate ( templateDataSource ) ; Document document = DocumentHelper . parseText ( templateContent ) ; List < Element > sheetElements = document . getRootElement ( ) . elements ( WorkbookElement . SHEET . getValue ( ) ) ; for ( Element sheetElement : sheetElements ) { SheetWriter sheetWriter = workbookWriter . createSheetWriter ( ) ; List < Element > rowElements = sheetElement . elements ( ) ; int realRowIndex = 0 ; processSheet ( sheetElement , sheetWriter ) ; for ( int rowIndex = 0 ; rowIndex < rowElements . size ( ) ; rowIndex ++ ) { Element rowElement = rowElements . get ( rowIndex ) ; int assignedRowGaps = StyleUtils . safeInteger ( rowElement . attributeValue ( WorkbookAttribute . ROW_GAPS . getValue ( ) ) ) ; realRowIndex += assignedRowGaps ; if ( rowElement . getName ( ) . equals ( WorkbookElement . ROW . getValue ( ) ) ) { processRowElement ( realRowIndex + rowIndex , rowElement , sheetWriter ) ; } else if ( rowElement . getName ( ) . equals ( WorkbookElement . DATA_TABLE . getValue ( ) ) ) { realRowIndex = processDataTableElement ( realRowIndex , rowElement , sheetWriter ) ; } } } workbookWriter . setActiveSheet ( 0 ) ; workbookWriter . save ( new FileOutputStream ( excelFile ) ) ; }
The main method for Excel file generating.
The main method for Excel file generating .
// The gaps defined of row will be effecting the realRowIndex. // The DataTable has multiple rows, so the realRowIndex will be changed after it generated.