Saturday 30 January 2016

How to export the specific columns in excel

This blog we will see how to export the specific columns in exported excel using af:setPropertyListener in ADF page.
In real time example sometimes we need to hide the column in exported excel.
In ADF export to excel by default it will export all the columns. But for not exporting the specific columns we need use the below code inside button

<af:commandButton text="Export to Excel"
                          binding="#{backingBeanScope.backing_ExportToExl.cb1}"
                          id="cb1">
            <af:setPropertyListener from="true"
                                                       to="#{pageFlowScope.hideColumn}"
                                                       type="action"/>
            <af:exportCollectionActionListener type="excelHTML" exportedId="t1"
                                                                            filename="Exporthidecolumnexl.xls"/>
            <af:setPropertyListener from="false"
                                                       to="#{pageFlowScope.hideColumn}"
                                                       type="action"/>
 </af:commandButton>

Set visible property in column like the below code

<af:column sortProperty="#{bindings.EmployeesVO1.hints.FirstName.name}"
                     sortable="false" visible="#{pageFlowScope.hideColumn ne true}"
                     headerText="#{bindings.EmployeesVO1.hints.FirstName.label}"
                     id="c2">
            <af:outputText value="#{row.FirstName}" id="ot4"/>
 </af:column>

Now run your application and click on the export to excel button, it will export the specific columns only

You Can download the code: Download

Thanks...