简体   繁体   中英

PrimeFaces 12 DataExporter decimal numbers xls

When updating to PrimeFaces 12, DataExporter presented an error in formatting decimal numbers in xls. Example: 50.00 is being printed 5,000 Note: the attempt below solved the problem locally (win10), but the problem persists on the server.

<f:facet name="header">
    <div align="center">
        <p:outputPanel style="float: right;">
            <h:commandLink id="gerarXls" styleClass="table-button generateXls">
                <p:graphicImage name="/images/table-icons/file-xls.svg"/>
                <p:dataExporter type="xls" target="datatableOrdemServico" fileName="Ordens de Servico"
                                options="#{dataExporterCustomizedView.excelOpt}"/>
            </h:commandLink>
        </p:outputPanel>
    </div>
</f:facet>
<p:column width="50" style="text-align: right"
          sortBy="#{ordemServico.totalGeral}" filterMatchMode="contains" filterBy="#{ordemServico.totalGeral}">
    <f:facet name="header">
        <h:outputText value="Total OS"/>
    </f:facet>
    <h:outputText value="#{ordemServico.totalGeral}" >
        <f:convertNumber minFractionDigits="2" locale="pt-BR"/>
    </h:outputText>
</p:column>
public class DataExporterCustomizedView implements Serializable {

    private ExcelOptions excelOpt;

    @PostConstruct
    public void init() {
        excelOpt = new ExcelOptions();

        excelOpt.setFacetBgColor("#F88017");
        excelOpt.setFacetFontSize("10");
        excelOpt.setFacetFontColor("#0000ff");
        excelOpt.setFacetFontStyle("BOLD");
        excelOpt.setCellFontColor("#00ff00");
        excelOpt.setCellFontSize("8");
        excelOpt.setStronglyTypedCells(true);
        excelOpt.setNumberFormat(new DecimalFormat("#,##0.00"));
        excelOpt.setCurrencyFormat((DecimalFormat) DecimalFormat.getCurrencyInstance(new Locale("pt", "BR")));
    }
public ExcelOptions getExcelOpt() {
        return excelOpt;
    }
}

From this ticket: https://github.com/primefaces/primefaces/issues/8961

Setting a custom per cell basis is not supported and is out of scope of this issue.

Currently, DataExporter detection feature only considers the property "CurrencyFormat" or "DecimalFormat" in ExcelOptions or, if it's not defined, in faces-config.xml.

Or by setting it in faces-config.xml faces-config.xml

<locale-config>
    <default-locale>pt_BR</default-locale>
</locale-config>

My Guess: Your server is in a differnet locale so that is what Faces is defaulting to because you are missing the explicit locale setting in your faces-config.xml.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM