<mvc:View controllerName="com.test.ReadFromExcel.controller.MainView" xmlns:mvc="sap.ui.core.mvc" displayBlock="true" xmlns="sap.m"
xmlns:u="sap.ui.unified">
<Shell id="shell">
<App id="app">
<pages>
<Page id="page" title="Read From Excel">
<customHeader>
<Bar>
<contentMiddle>
<Label text="Read Data From Excel"/>
</contentMiddle>
<contentRight>
<u:FileUploader id="FileUploaderId" sameFilenameAllowed="true" iconOnly="false" buttonOnly="true" fileType="XLSX,xlsx"
icon="sap-icon://upload" iconFirst="true" style="Emphasized" change="onUpload"/>
</contentRight>
</Bar>
</customHeader>
<content>
<Table items="{localModel>/items}">
<columns>
<Column>
<Label text="Name"/>
</Column>
<Column>
<Label text="Age"/>
</Column>
<Column>
<Label text="Job"/>
</Column>
<Column>
<Label text="Address"/>
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{localModel>Name}"/>
<Text text="{localModel>Age}"/>
<Text text="{localModel>Job}"/>
<Text text="{localModel>Address}"/>
</cells>
</ColumnListItem>
</items>
</Table>
</content>
</Page>
</pages>
</App>
</Shell>
</mvc:View>
'
onInit: function () {
this.localModel = new sap.ui.model.json.JSONModel();
this.getView().setModel(this.localModel, "localModel");
},
onUpload: function (e) {
this._import(e.getParameter("files") && e.getParameter("files")[0]);
},
_import: function (file) {
var that = this;
var excelData = {};
if (file && window.FileReader) {
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
var workbook = XLSX.read(data, {
type: 'binary'
});
workbook.SheetNames.forEach(function (sheetName) {
// Here is your object for every sheet in workbook
excelData = XLSX.utils.sheet_to_row_object_array(workbook.Sheets[sheetName]);
});
// Setting the data to the local model
that.localModel.setData({
items: excelData
});
that.localModel.refresh(true);
};
reader.onerror = function (ex) {
console.log(ex);
};
reader.readAsBinaryString(file);
}
}
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.10.0/jszip.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.10.0/xlsx.js"></script>
...
</head>
<body class="sapUiBody">
...
</body>
</html>


var jQueryScript = document.createElement('script');
jQueryScript.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.10.0/jszip.js');
document.head.appendChild(jQueryScript);
var jQueryScript = document.createElement('script');
jQueryScript.setAttribute('src', 'https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.10.0/xlsx.js');
document.head.appendChild(jQueryScript);You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 27 | |
| 24 | |
| 20 | |
| 19 | |
| 14 | |
| 13 | |
| 13 | |
| 12 | |
| 12 | |
| 11 |