Thursday 12 September 2013

How to Export adf table record in xls file using exportCollectionActionListener tag


Data of the collection components in ADF such as table, tree or treeTable can easily be exported in the form of xls file using ADF exportCollectionActionListener tag. It allows action events to export data from the colleection component.

<af:exportCollectionActionListener/> id attribute will refer to the collection component Id.

Find the sample code snippet for exporting department table records.

<af:panelCollection id="pc1" styleClass="AFStretchWidth">
            <f:facet name="toolbar">
              <af:toolbar id="t2">
                <af:commandToolbarButton text="Export" id="ctb1">
                  <af:exportCollectionActionListener type="excelHTML"
                                                     exportedId="table"
                                                     filename="DepartmentExcel"/>
                </af:commandToolbarButton>
              </af:toolbar>
            </f:facet>

            <af:table
id="table" ....
            ..................................  ...................
            ............ >
 </af:panelCollection>

By default the extension of the file downloaded will be xls. We can also export the record in doc format by just giving name of a file such as DepartmentExcel.doc in the attribute filename.




*Comments and feedback are most welcomed, Thanks.

5 comments:

  1. How do you import that Excel data now back into your ADF table (database)?

    ReplyDelete
  2. Greg,

    To import excel back to the ADF table you can use file upload component and will require some coding to parse it.

    Pasted link for reading excel using java:

    http://www.vogella.com/tutorials/JavaExcel/article.html

    ReplyDelete
  3. Hi Gopal,
    Is there a way to directly export to excel from the data control on button click?
    Thanks
    Ray

    ReplyDelete
  4. Ray,

    You can also use af:fileDownloadActionListener with command button. Specify content type as "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    And add custom method to read Iterator using java and export to excel

    ReplyDelete
  5. Hi,

    In adf table , one of the column has stiosignal with hovertext for it and number beside it in same column. But when i export it to excel i want only number to displayed in that column. But issue is both hovertext and number is displaying in that column.PLaese do nsome needful.
    Thanks

    ReplyDelete