Primefaces, how to export Header and Footer from dataTable

0

I have a dataTable that uses HeaderRow and SummaryRow, as follows:

 <p:dataTable var="dre" value="#{planoContasControle.listaPlanoContas}" sortBy="#{dre.dre.id}" id="dre" expandableRowGroups="true">
                        <p:headerRow>
                            <p:column colspan="3">
                                <h:outputText value="#{dre.dre.descricao}" />
                            </p:column>
                        </p:headerRow>
                        <p:column headerText="Cód." width="100">
                            <h:outputText value="#{dre.id}" />
                        </p:column>
                        <p:column headerText="Descrição" width="800">
                            <h:outputText value="#{dre.descricao}" />
                        </p:column>

                        <p:column headerText="Total (R$)" width="150" style="text-align: right;">
                            <h:outputText value="#{dre.total}">
                                <f:convertNumber minFractionDigits="2" maxFractionDigits="2"/>
                            </h:outputText>
                        </p:column>
                        <p:summaryRow>
                            <p:column colspan="2" style="text-align:right">
                                <h:outputText value="Total (R$):" style="color: white" />
                            </p:column>
                            <p:column>
                                <h:outputText value="#{dre.dre.total}" style="color: white">
                                    <f:convertNumber minFractionDigits="2" maxFractionDigits="2"/>
                                </h:outputText>
                            </p:column>
                        </p:summaryRow>
                    </p:dataTable>

I also use a postProcessXLS to export to Excel, but HeaderRow and SummaryRow are not exported.

postProcessXLS:

public void postProcessXLS(Object document) {
    HSSFWorkbook wb = (HSSFWorkbook) document;
    HSSFSheet sheet = wb.getSheetAt(0);
    HSSFRow header = sheet.getRow(0);

    HSSFCellStyle cellStyleFormat = wb.createCellStyle();

    HSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setFillForegroundColor(HSSFColor.GREY_25_PERCENT.index);
    cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    cellStyle.setBorderBottom((short) 1);
    cellStyle.setBorderLeft((short) 1);
    cellStyle.setBorderRight((short) 1);
    cellStyle.setBorderTop((short) 1);

    for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) {
        HSSFCell cell = header.getCell(i);
        cell.setCellStyle(cellStyle);

// cell.setCellValue (titles [i]);             sheet.autoSizeColumn (i);         }

    HSSFCellStyle rowCellStyle = wb.createCellStyle();
    rowCellStyle.setBorderBottom((short) 1);
    rowCellStyle.setBorderLeft((short) 1);
    rowCellStyle.setBorderRight((short) 1);
    rowCellStyle.setBorderTop((short) 1);

    for (int i = 1; i <= sheet.getLastRowNum(); i++) {

        HSSFRow row = sheet.getRow(i);

        HSSFCellStyle style = wb.createCellStyle();
        style.setFillForegroundColor(i == 0 ? HSSFColor.AQUA.index
                : i % 2 == 0 ? HSSFColor.PALE_BLUE.index
                        : HSSFColor.WHITE.index);
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        if (row != null) {

            for (int j = 0; j <= row.getPhysicalNumberOfCells(); j++) {
                HSSFCell cell = row.getCell(j);
                if (cell != null) {
                    cell.setCellStyle(style);
                }
            }
        }
    }
}

Would anyone have an idea how to solve this?

    
asked by anonymous 07.11.2018 / 12:24

0 answers