JunWu,
I followed this thread Read contents of Excel file into Sapui5 table | SCN
i downloaded Download xlsx.js and jszip.js from the above URL and added into the my Application. PFA my application.
I created that application in WEBIDE. Please check and help me.
Controller
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function(Controller) {
"use strict";
jQuery.sap.require("UploadExcel.excelFiles.xlsx");
jQuery.sap.require("UploadExcel.excelFiles.jszip");
return Controller.extend("UploadExcel.controller.uploadExcel", {
uploadFileCSV: function(e) {
this._uploadFileCSVBtn(e.getParameter("files") && e.getParameter("files")[0]);
},
_uploadFileCSVBtn: function(file) {
if (file && window.FileReader) {
var reader = new FileReader();
var result = {},
data;
reader.onload = function(e) {
data = e.target.result;
var wb = XLSX.read(data, {
type: 'binary'
});
wb.SheetNames.forEach(function(sheetName) {
var roa = XLSX.utils.sheet_to_row_object_array(wb.Sheets[sheetName]);
if (roa.length > 0) {
result[sheetName] = roa;
}
});
return result;
}
reader.readAsBinaryString(file);
}
}
});
});
View
<mvc:View controllerName="UploadExcel.controller.uploadExcel" 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">
<App>
<pages>
<Page title="{i18n>title}">
<content>
<l:VerticalLayout id="vlayoutId">
<u:FileUploader id="fileupload" name="File Uploader" useMultipart="false" sendXHR="true"
change="uploadFileCSV" sameFilenameAllowed="false"/>
<Button id="btnUpload" press="uploadFileCSV" text="Upload"></Button>
</l:VerticalLayout>
</content>
</Page>
</pages>
</App>
</mvc:View>
Application Structure: