Hello Friends,
I need some help from you. How to read the data from the .xlsx file (Examp: “VijayTest. .xlsx) using sap/ui/unified/FileUploader
Using below code its works for CVS format. When I try to upload excel file its not working. Please help me
In XML View
<mvc:View xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:u="sap.ui.unified"
xmlns:l="sap.ui.layout" controllerName="SimpleUI5.controller.fisrtView">
<App>
<pages>
<Page id="fileId" title="{i18n>title}">
<content>
<l:VerticalLayout id="vlayoutId">
<u:FileUploader id="fileupload" name="File Uploader" useMultipart="false" sendXHR="true"
change="uploadFileCSV1" sameFilenameAllowed="false"/>
<Button id="btnUpload" press="uploadFileCSVBtn" text="Upload"></Button>
</l:VerticalLayout>
</content>
</Page>
</pages>
</App>
</mvc:View
- Controller.js
uploadFileCSV1:function(oEvent){
var that = this;
var file = oEvent.getParameter("files")[0];
if (file && window.FileReader){
var reader = new FileReader();
reader.onload = function(evn) {
var strCSV = evn.target.result; //string in CSV
that.csvJSON(strCSV);
};
reader.readAsText(file);
}
},
csvJSON:function(csv)
{
var lines = csv.split("\n");
var result = [];
var headers = lines[0].split(",");
for (var i = 1; i < lines.length; i++)
{
var obj = {};
var currentline = lines[i].split(",");
for (var j = 0; j < headers.length; j++)
{
obj[headers[j]] = currentline[j];
}
result.push(obj);
}
// var oStringResult = JSON.stringify(result);
//var oFinalResult = JSON.parse(oStringResult.replace(/\\r/g, ""));
this.oStringResult = JSON.stringify(result);
this.oFinalResult = JSON.parse(this.oStringResult.replace(/\r/g, ""));
//sap.ui.getCore().getModel().setProperty("/", oFinalResult);
},
uploadFileCSVBtn : function(){
var oModel = this.oStringResult;
var finalModel = this.oFinalResult;
}
Excel Sheet Format:
Error Message: Getting Wrong data : var strCSV = evn.target.result; //string in CSV
Regards
Vijay K