If you have users that like reports, I have good news to you! Export table to Excel is very simple when you use Oracle ADF. You just have to use the exportCollectionActionListener tag. This way, you allow an action source (<commandButton>, <commandLink>, etc.) to export data from a collection component (<table>, <tree>, <treeTable>) into an external format in declarative way.
Download the sample application – ExportTableApp.zip – that export rows (all or selected) from table into Excel report. This application shows the table as printable page too.
Create a Fusion Web Application (ADF) like image below.
Open the ViewEmployees.jspx file.
Navigate to Data Control pane, drag the EmployeesView1 and drop inside the page as ADF Read-only Table. Mark Multiple Rows, Enable Sorting and Enable Filtering options from Edit Table Columns Dialog, and click on OK to create the table.
Select the table and set the ID property as “tEmployees”.
Now we need to surround table with Panel Collection, a component that contains certain controls / features to work with collection components like <table>, <treeTable> and <tree>. Go to Structure pane, right-click on af:table “tEmployees” and select Surround With. Select Panel Collection and click on OK.
To create menu with export options, go to Structure pane, right-click on menus facet from af:panelCollection, and select Insert inside menus | Menu. Set the Text property as “File”.
Right-click on af:menu “File” and select Insert inside af:menu – File | Menu Item. Repeat the previous steps to add three Menu Items. Set the Text porpeties as “Export to Excel (All Rows)”, “Export to Excel (Selected Rows)” and “Show as Printable Page”.
Go to Component Palette | Operations, drag the Export Collection Action Listener and drop inside the af:commandMenuItem “Export to Excel (All Rows)” from Structure Pane.
In Insert Export Collection Action Listener Dialog, click on Edit from the ExportedId property, navigate through the nodes to find af:table “tEmployees” and click on OK. Set the Type property as excelHTML. Click on Ok.
Set the properties of the af:exportCollectionActionListener.
Repeat the previous steps for the af:commandMenuItem “Export to Excel (Selected Rows)”, and set the properties of the af:exportCollectionActionListener.
Drag the Show Printable Page Behavior and drop inside the af:commandMenuItem “Show as Printable Page” from Structure Pane.
The Structure pane should look like this image.
Now, it is time to test the application!
Right-click on ViewEmployees.jspx page and select Run.
To export all rows, go to menu and select Export to Excel (All Rows) option.
To export selected rows, select some rows, go to menu and select Export to Excel (Selected Rows) option.
To show table as printable page, go to menu and select Show as Printable Page option. This way, you can save the table as image or PDF file.