how to download excel file from odata into sapui5
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.
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
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
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); }
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK