cancel
Showing results for 
Search instead for 
Did you mean: 

No additional worksheet with metadata is added in sap.ui.export.SpreadSheet

devinreid5
Discoverer
0 Kudos

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();

Accepted Solutions (0)

Answers (1)

Answers (1)

rlachemann
Explorer
0 Kudos

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.

Vanessa23
Advisor
Advisor
0 Kudos

Can it provide the function createWorkbook? I have the same problem