on 10-22-2020 11:18 PM
I am following exactly the code found here in the API Reference for sap.ui.export.SpreadSheet. No error is occurring, but I cannot generate the second Worksheet in the Excel file that contains the Meta Data info. The Excel file gets generated but there is no metadata tab. Does this functionality work for anyone else? What am I doing wrong? See the code below:
jQuery.sap.require("sap.ui.export.SpreadSheet"); var mDataSource = [{name: "Devin", salary: "50"}]; var aColumns = []; aColumns.push({ label: "Name", property: "name" }); aColumns.push({ label: "Salary", property: "salary", type: "number", scale: 2 }); var mSettings = { workbook: { columns: aColumns, context: { application: 'Debug Test Application', version: '1.82.1', title: 'Some random title', modifiedBy: 'John Doe', metaSheetName: 'Custom metadata', metainfo: [{ name: 'Grouped Properties', items: [{ key: 'administrator', value: 'Foo Bar' }, { key: 'user', value: 'John Doe' }, { key: 'server', value: 'server.domain.local' }] }, { name: 'Another Group', items: [{ key: 'property', value: 'value' }, { key: 'some', value: 'text' }, { key: 'fu', value: 'bar' }] }] }, hierarchyLevel: 'level' }, dataSource: mDataSource, fileName: "salary.xlsx", count: 1 }; var oSpreadsheet = new sap.ui.export.SpreadSheet(mSettings); oSpreadsheet.attachBeforeExport = function(oEvent){ var event = oEvent; }; oSpreadsheet.build();
Please find below an example of what I used to make it work.
I noticed that your workbook context and dataSource are different to mine.
exportSpreadsheet: function(oData) {
var vFilename = "MyFile_" + oData.Datlo + "_" + oData.Timlo + ".xlsx";
var aCols, oRowBinding, oSettings, oSheet, oTable;
if (!this._oTable) {
this._oTable = this.byId("listReport");
}
oTable = this._oTable;
oRowBinding = oTable._oTable.getBinding("items");
if (oRowBinding) {
aCols = this.createColumnConfig();
var sWorkbook = this.createWorkbook(oData,aCols);
var oModel = this.getOwnerComponent().getModel();
var serviceUrl = oModel.sServiceUrl;
var listBinding = this.byId("listReport")._oTable.getBinding("items");
oSettings = {
workbook: sWorkbook,
dataSource: {
type: "OData",
useBatch: true,
serviceUrl: serviceUrl,
headers: listBinding.getModel().getHeaders(),
dataUrl: listBinding.getDownloadUrl(),
count: listBinding.getLength(),
/*E.g.*/ sizeLimit: 31
},
fileName: vFilename,
worker: true
};
oSheet = new sap.ui.export.Spreadsheet(oSettings);
oSheet.build().finally(function() {
oSheet.destroy();
});
} else {
sap.m.MessageToast.show("No Data in Table!", {
duration: 3000,
at: sap.ui.core.Popup.Dock.CenterCenter,
width: "15rem"
});
}
},
Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.