Skip to Content
avatar image
Former Member

Export to excel -ExportTypeCSV , data formatted prepending a single quote

Hi All,

I am able to export table data to excel dynamically, but some of the data like long numbers and negative values are formatted

Below is the UI Table data

exported data to CSV

when I select the long values it showing the proper value on top of excel, and -ve values are appended with '......

Code :

jQuery.sap.require("sap.ui.core.util.Export");
jQuery.sap.require("sap.ui.core.util.ExportTypeCSV");
sap.ui.define([
'jquery.sap.global',
'sap/ui/core/mvc/Controller',
'sap/ui/model/json/JSONModel'
], function(jQuery, Controller, JSONModel) {
"use strict";
var vSrcMATNR;
var oEvtBus = sap.ui.getCore().getEventBus();
var TableController = Controller.extend("UtilLoad.Util", {
exportToExcel: function(oTable) {
var that = this;
var aColumns = oTable.getColumns();
var aItems = oTable.getItems();
var aTemplate = [];
for (var i = 0; i < aColumns.length; i++) {
var oColumn = {
name: aColumns[i].getHeader().getText(),
template: {
content: {
path: null
}
}
};
if (aItems.length > 0) {
oColumn.template.content.path = aItems[0].getCells()[i].getBinding("text").getPath();
}
aTemplate.push(oColumn);
}
var oExport = new sap.ui.core.util.Export({
// Type that will be used to generate the content. Own ExportType’s can be created to support other formats
exportType: new sap.ui.core.util.ExportTypeCSV({
separatorChar : ",",
                charset : "utf-8"
}),
// Pass in the model created above
models: oTable.getModel(),
// binding information for the rows aggregation
rows: {
path: "/"
},
// column definitions with column name and binding info for the content
columns: aTemplate
});
oExport.saveFile().always(function() {
this.destroy();
});
},
fnDate: function(sDate) {
if (sDate) {
var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({
pattern: "dd-MM-yyyy"
});
return oDateFormat.format(new Date(sDate));
} else {
return sDate;
}
}
});
return TableController;
});

from SAP documentation advicing to use data export functionality , please what is it and how

https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.core.util.ExportTypeCSV.html

Thanks

Rajesh

ui-tabale-data.jpg (75.2 kB)
ui-tabale-data.jpg (75.2 kB)
exportexcel.jpg (98.0 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Apr 05, 2017 at 11:46 AM

    Hi All,

    Issue is fixed with below solution

    convert that numbers into string by giving Tab Space between double quotes in the return statement

    http://stackoverflow.com/questions/43121703/sapui5-fiori-export-to-excel-exporttypecsv-data-formatted-prepending-a-single?noredirect=1#comment73473507_43121703

    Solution from SAP

    SAP note : 2452786 advising to upgrade SAPUI5 to latest patch

    Thanks

    Rajesh

    Add comment
    10|10000 characters needed characters exceeded