cancel
Showing results for 
Search instead for 
Did you mean: 

exportData() method of sap.ui.table.Table exporting Excel with empty values.

Sijin_Chandran
Active Contributor
0 Kudos

Hello UI5 Gurus,

In my view I have a table created using sap.ui.table library , I have given it a custom id "TAB2"

Now in my controller side I have written code for Downloading Table control data, I have attached screenshot.

I am getting Excel file downloaded , but its with empty contents.

Can anyone please suggest, what needs to be rectified.

Thanks,

Sijin

Accepted Solutions (0)

Answers (3)

Answers (3)

JohnPaulLiberal
Explorer
0 Kudos

Hi Sijin,

Please look at the following code:

OnExcelAssets: function(oEvt){
            var oModel = this.getView().getModel("masterView");
            var oData = oModel.getData();
            var oTab = this.getView().byId("TAB2");
            var oBinding = oTab.getBinding("items");
            var oExport = new Export({
                exportType : new ExportTypeCSV({
                    separatorChar : ";"
                }),
                models : this.getView().getModel("masterView"),
                rows : {
                    path : "/myAssets",
                    filters: oBinding.aFilters
                },
                columns : [{
                    name : this.getResourceBundle().getText("actCol1"),
                    template : {
                        content : "{Anln1}"
                    }
                }, {
                    name : this.getResourceBundle().getText("actCol2"),
                    template : {
                        content : "{Txt50}"
                    }
                },{
                    name : this.getResourceBundle().getText("actCol6"),
                    template : {
                        content : "{Zzestadotxt}"
                    }    
                }]
            });
            this.onExcel(oExport);
        },

onExcel: sap.m.Table.prototype.exportData || function(oExport){
            var vText = this.getResourceBundle().getText("errorPressExcel");
            // download exported file
            oExport.saveFile().catch(function(oError) {
                //Handle your error
            }).then(function() {
                oExport.destroy();
            });
        },

Regards,

John.

Ivan-Mirisola
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Sijin,

Table objects are tricky. Have you tried this:

var oTable = this.getView().byID("TAB2");
// oTableRows will contain the visible data on your table in json format - so you can pass it to the sap.ui.core.util.ExportTypeCSV
var oTableRows = oTable.getBindingInfo("rows");

This is just the beginning of it. I had to develop an utility library to be able to export data. That is because the view component (table) will contain only the displayed values. If you perform filters, or sorters of any kind, your export will be useless. Let's say you limit the table to 5 rows. Your export will have just 5 rows.

The correct solution should be to base your export function on what the full OData output. So you need to retrieve the filters, sorters and selected columns to "mimic" the data the user "thinks" they are seeing and then call the service again passing the values back to the export functionality.

Regards,
Iivan

0 Kudos

Hi Ivan,

i agree to your point of view in calling the odata service to download the data in excel. does this can be achieved to the sap.ui.table/ grid table in the object page table?

I have to enable download button in object page section- table data in object page with fiori version 1.52.

is this possible?

thanks,

Soumya

Sijin_Chandran
Active Contributor
0 Kudos

I tried as mentioned in SAP document also but it is also giving empty contents.

https://help.sap.com/saphelp_nw74/helpdata/en/f1/ee7a8b2102415bb0d34268046cd3ea/frameset.htm