PrimeFaces DataExporter to XLS for multiple tables

2.6k views Asked by At

Am trying to Export XLS format from multiple tables. I have browsed and used some code, But its not working. Using primefaces extensions code is there but complete code is not there it seems in this link. I need solution for this.

Code i have used : Tbl1, Tbl2, Tbl3 are table widgetVar's.

    <p:commandLink id="xls" ajax="false" >  
                <p:graphicImage value="/images/excel.png" />   
                <pe:exporter type="xlsx" target="Tbl1, Tbl2, Tbl3" fileName="tables"/>
    </p:commandLink>
2

There are 2 answers

2
Kukeltje On

You should not address them by widgetVar. From the PrimeFaces Extensions Exporter (emphasis mine):

Here we can export multiple tables by providing multiple datatable server ids with the delimiter as "comma"(or ",").

0
Dagon On

I work with primefaces 6.2 and this works for me (I’m not sure about other versions) without use primefaces extension

<p:dataTable id="tbl1" value="#{ManagedBean.listValues}" var="vt">
    <p:column headerText="LabelPrint">
        <h:outputText value="#{vt.id}"/> 
    </p:column>
</p:dataTable>

<p:dataTable id="tbl2" value="#{ManagedBean.otherList}" var="vt2">
     <p:column headerText="Name Field Print">
         <h:outputText value="#{vt2.name}"/> 
     </p:column>
</p:dataTable>

<h:commandLink>
 <p:graphicImage url="#{resource['/images/icons/table-xls.png']}"/>
 <p:dataExporter type="xls" target="tbl1, tbl2" fileName="My Data" pageOnly="true" />
</h:commandLink>

You separate your "id" of tables for export with (,) in attribute target of p:dataexporter object.