Hi All,
I am new to sapui5. I have downloading ui5 tables as CSV format by refereed below link.
Export sap.ui.table.Table as CSV
Those tables data i am getting from XSODATA Service. service returning result as Json Format.
Now the problem is my CSV file having %20 and %2 instead of space and comma values(if I remove enCodeURIComponent, values are misplacing in excel cells which is values having comma and space). I have added my code snippets below.
View.js
tableObj = sap.ui.getCore().byId("myTableId"); var oModel = new sap.ui.model.json.JSONModel(); jQuery.ajax({ url: url, dataType: "json", beforeSend: function(){ tableObj.setBusy(true); }, success: function(data, textStatus, jqXHR) { totalResultsCount = data.d.results.length; var b64text = generateTableCSV(tableObj,data.d.results); sap.ui.getCore().byId("id_exportcsvbutton").setHref('data:application/csv;charset=utf-8;base64,' + (Base64.encode(b64text))); setTimeout(function (){ $( "#Myprgs_exportcsv" ).attr('download', 'MyProgress.csv'); },1000); error: function(jqXHR, textStatus, errorThrown) { }, complete: function(){ tableObj.setBusy(false); } });
downloadExcel.js
function generateTableCSV(table, jsonData) { for (var i = 0; i < table.getColumns().length; i++) { info += encodeURIComponent(table.getColumns()[i].getLabel().getText()) + ','; } } info += '\r\n'; if (jsonData.length != undefined) { for (var j = 0; j < jsonData.length; j++) { for (var i = 0; i < table.getColumns().length; i++) { var dk= table.getColumns()[i].getTemplate().getBinding( 'value').sPath; if (table.getColumns()[i].getTemplate() != undefined && table.getColumns()[i].getTemplate().getBinding( 'value') != undefined) { var valor = eval('jsonData[j].'+ dk); info += encodeURIComponent(valor) + ','; } } info += '\r\n'; } } else { $.each(jsonData, function(key, value) { for (var i = 0; i < table.getColumns().length; i++) { var dk= table.getColumns()[i].getTemplate().getBinding('value').sPath; if (table.getColumns()[i].getTemplate() != undefined && table.getColumns()[i].getTemplate().getBinding('text') != undefined) { var valor = eval('jsonData[j].'+ dk); info += encodeURIComponent(valor) + ','; } } info += '\r\n'; }); } return info; }
Base 64 Util.js
I have using same code which is in this link Export sap.ui.table.Table as CSV
Base 64 Util.
also I have attached my CSV output as screenshot. Can some one help me to resolve this?? Any help would be greatly appreciated.
Thanks,
Jayan.M