Skip to Content

Help needed for alignment of data in Excel file -SAP UI5

Hi All,

I have created sap.m.Table with static Json data and created the button for exporting the table data into .xls file. I am able to download the .xls file but data is not aligned properly in .xls file. screenshot shown below.

Could you please help me on this to align data in .xls file properly. I need file with proper alignment. Screenshot shown below

I have written code in controller file.

onExportExcel:function(){ var data = this.getView().byId("idProductsTable").getModel("login1").getData(); this.JSONToCSVConvertor(data,'Report', true); }, JSONToCSVConvertor:function(JSONData, ReportTitle, ShowLabel){ // If JSONData is not an object then JSON.parse will parse the JSON string in an Object var arrData = typeof JSONData.TableData!= 'object' ?JSON.parse(JSONData.TableData) : JSONData.TableData; var CSV = ""; // Set Report title in first row or line CSV+= ReportTitle + '\r\n\n'; if (ShowLabel) { var row = ""; row= row.slice(0, -1); } row += ',' + this.getView().byId("ProductId").getText() + ','; row += ',' + this.getView().byId("QuantityId").getText() + ','; row += ',' + this.getView().byId("DeliveyId").getText() + ','; row += ',' + this.getView().byId("PriceId").getText() + ''; CSV+= row + '\r\n';

for (var i = 0; i <arrData.length; i++) {

var row = ""; row+= '"' + arrData[i].product + ',' + arrData[i].quantity +'",' + arrData[i].DeliveryDate +'",' + arrData[i].price +'';

row.slice(0,row.length - 1);

CSV+= row + '\r\n'; }

if (CSV == "") {

alert("Invalid data"); return; }

var fileName = "Product_"; fileName+= ReportTitle.replace(/ /g, "_"); // Initialize file format you want csv or xls var uri = "data:text/csv;charset=utf-8," + escape(CSV); var link =document.createElement("a"); link.href= uri; link.style= "visibility:hidden"; link.download= fileName + ".xls"; document.body.appendChild(link); link.click(); document.body.removeChild(link); }

Regards,

Manjunath Nennevath

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers