Tuesday, November 2, 2010

ADF UI - Implementing 'Export to Excel' functionality

Here, we'll see how to implement 'Export to Excel' functionality for ADF tables. For example you have a search results table and you want to export the search results to excel sheet on clicking the button 'Export to Excel'.

To implement this, Drag and drop <af:exportCollectionActionListener> on 'Export to Excel' button. and specify exportedId="<search_results_table_id>" and type="excelHTML". Give fileName="excel_file_name.xls" and title="excel_sheet_name_within_excel_file".


The 'Export to Excel' toolbar button in 'Structure' window:

Here is the code:
<af:commandToolbarButton text="Export to Excel" id="commandToolbarButton2" disabled="#{bindings.EmpDeptVO.currentRow==null}" partialTriggers="t1"> <af:exportCollectionActionListener type="excelHTML" exportedId="t1" filename="SearchResults.xls" title="Search Results"/> </af:commandToolbarButton>

That's it. Now, when you run the page and click on 'Export to Excel' button, it'll generate the excel file and asks to open or save the Excel.

Enjoy!!

11 comments:

  1. I'm using this one. One issue I observed with this is, I have a af:column with a af:inputText, af:commandButton & a popup inside it. Functionality is, when user clicks on commandButton, he sees he popup which has value as entered in the af:inputText.
    When I export this table to an excel, I get to see duplicate values for this column. Somehow its assuming two values.

    Thanks,
    Bhargav.

    ReplyDelete
  2. Hi Bhargav,

    You can try having popup outside the table. You can still achieve the same required functionality with the popup outside the af:table. You can either invoke the popup using af:showPopupBehavior or programatically.

    -Murali.

    ReplyDelete
  3. Hi,
    I am using the above functionality and the file generated is html and MS Excel has trouble complaining its not a valid format. Can anything be done to troubleshoot this?

    Thanks

    ReplyDelete
  4. Hi Murali,

    While exporting the table (Search results), Framework doesn't write the search criteria that been entered to get the results.

    Do we need to handle this through code for writing the search criteria to excel sheet ?

    Regards,
    Sai Yeluri.

    ReplyDelete
  5. @sai - Export to Excel only exports the search results into excel sheet. It won't export the search criteria.

    ReplyDelete
  6. i am not getting the column names in the generated excel. Help!!!

    ReplyDelete
  7. Hi Murali,
    Do you know any way to export contents other than tables or trees into excel in ADF? In my case I need to add export functionality for Business Intelligence objects but I couldn't find any way to do so.

    ReplyDelete
  8. Hi,
    This is working fine , bt i want to check my rows are not empty. can u help me in this

    ReplyDelete

Related Posts with Thumbnails