1

how to download excel file from odata into sapui5

 1 year ago
source link: https://answers.sap.com/questions/13707299/how-to-download-excel-file-from-odata-into-sapui5.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Search Questions and Answers
yesterday

how to download excel file from odata into sapui5

39 Views


Hi Experts,

When I click the button in my application OData service should call and download the excel file directly.

Please help me. Thanks in advance.



Thanks & Regards

Srinivas Raju





2 Answers
Sort by:

Hi Raju,

This can be achieved by Creating a Separate entity for the Data's to be downloaded and at UI5 write a logic to download Entity details in Excel.

Thanks & Regards,

Thariq K I Mohamed

Hi allurisrinivas raju

Use below code for download data for excel format.

oData.results = your odata service read data.

onExport = Button click event

onInit: function () { 

var oModel = new JSONModel(odata.results); 

this.getView().setModel(oModel);
},

createColumnConfig: function () { 

return [ { 

label: 'ProductID', property: 'ProductID', type: EdmType.Number, scale: 0 

}, { 

label: 'ProductName', property: 'ProductName',width: '25' 

}, { 

label: 'UnitsInStock', property: 'UnitsInStock', width: '25' 

}, { 

label: 'UnitsOnOrder', property: 'UnitsOnOrder', width: '18' 

}, { 

label: 'SupplierID', property: 'SupplierID', type: EdmType.String 

}]; 

},
onExport: function () { 

var aCols, aProducts, oSettings, oSheet;
aCols = this.createColumnConfig(); 

aProducts = this.getView().getModel().getProperty('/'); 

oSettings = { 

workbook: { columns: aCols }, 

dataSource: aProducts, fileName: 'Promotion.xlsx', worker: false };

 oSheet = new Spreadsheet(oSettings); 

oSheet.build() .then(function () { 

MessageToast.show('Spreadsheet export has finished'); 

}) .finally(oSheet.destroy); 

}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK