Search code examples
primefacesdatatableprimefaces-datatable

How can I export numbers in the correct type using p:dataExporter?


I am using PrimeFaces dataExporter for exporting my datatable to an Excel file. The problem is that numbers are exported as text.

How can I export my numbers as integer and double?

    <p:column headerText="net_usd_sale">
        <h:outputText value="#{dizgi.net_usd_sale}" />
    </p:column>

    <p:column style="text-align: center" exportable="false">
   <f:facet name="header">
     <h:outputText value="Details" />
   </f:facet>
   <h:graphicImage value="/resources/images/details.png"  alt="details image" />

    </p:column>

</p:dataTable>
<h3>Export Page Data Only</h3>
    <h:commandLink>
        <p:graphicImage library="images" name="excel.png" width="24" />
        <p:dataExporter type="xls" target="tbl" fileName="dizgi" pageOnly="true"/>
    </h:commandLink>

    </h:form>

</html>   

Solution

  • There is an option to customize your dataExporter

       <h:commandLink id="excel">
        <p:graphicImage name="/demo/images/excel.png" />
        <p:dataExporter type="xls" target="tbl" fileName="cars" 
                 postProcessor="#{customizedDocumentsView.postProcessXLS}" />
    </h:commandLink>
    

    In post process event you can manipulate your work book. Check this link Primefaces DataExporter - Customized Documents