Skip to Content
0

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

Dec 12, 2017 at 12:21 PM

410

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Sijin Chandran Dec 12, 2017 at 12:23 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Dec 21, 2017 at 02:41 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
Ivan Mirisola
Dec 21, 2017 at 02:29 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded