How to upload CSV file data in SAPUI5 and SAP Fiori Applications


Hello everyone, in this blog we will show you how to upload CSV file data in SAPUI5 and SAP Fiori Applications. Lets get started.



You should have basic understanding on building SAPUI5 applications. To get all beginner tutorials please check here.

UI Controls used

  • File Uploader from sap.ui.unified library
  • Table and Button from sap.m library

Step-by-Step Procedure

1. Create a SAPUI5 application in Eclipse IDE with one view and a controller. You project structure will look like below.

SAPUI5 Project Structure 2. Go to index.html and copy the below code.

		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

		<script src="resources/sap-ui-core.js"
		<!-- only load the mobile lib "sap.m" and the "sap_bluecrystal" theme -->

			var app = new sap.m.App({initialPage:"idFileUpload1"});
			var page = sap.ui.view({id:"idFileUpload1", 
	<body class="sapUiBody" role="application">
		<div id="content"></div>

3. Go to FileUpload.view.xml file and copy the below code to build the view.

<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
	xmlns="sap.m" xmlns:u="sap.ui.unified" xmlns:l="sap.ui.layout.form"
	controllerName="fileupload.FileUpload" xmlns:html="">
	<Page title="Demo on CSV File Upload">
		<l:SimpleForm editable="true">
		  <Label text="File Name">
		 <u:FileUploader id="idfileUploader" width="50%"
		    sameFilenameAllowed="false" buttonText="" fileType="CSV"
		    placeholder="Choose a CSV file" style="Emphasized">
		<Button text="Upload" press="onUpload"></Button>

		<Table id="idTable" items="{/}">
			<Text text="{VBELN}"></Text>
			<Text text="{ERDAT}"></Text>
			<Text text="{VBTYP}"></Text>
			<Text text="{TRVOG}"></Text>
			<Text text="{AUART}"></Text>
			<Text text="Sales Document"></Text>
			<Text text="Date"></Text>
			<Text text="Type"></Text>
			<Text text="Sales Org"></Text>
			<Text text="Category"></Text>

4. Lets see what we have done in the previous step.We created the view to show File Uploader, Button and Table UI control.

5. Go to FileUpload.controller.js file and copy the below code.

sap.ui.controller("fileupload.FileUpload", {

    onUpload : function(e) {
	var fU = this.getView().byId("idfileUploader");
	var domRef = fU.getFocusDomRef();
	var file = domRef.files[0];
	// Create a File Reader object
	var reader = new FileReader();
	var t = this;
	reader.onload = function(e) {
	    var strCSV =;
	    var arrCSV = strCSV.match(/[\w .]+(?=,?)/g);
	    var noOfCols = 5;

	    // To ignore the first row which is header
	    var hdrRow = arrCSV.splice(0, noOfCols);

	    var data = [];
	    while (arrCSV.length > 0) {
		var obj = {};
		// extract remaining rows one by one
		var row = arrCSV.splice(0, noOfCols)
		for (var i = 0; i < row.length; i++) {
		    obj[hdrRow[i]] = row[i].trim()
		// push row to an array
	    // Bind the data to the Table
	    var oModel = new sap.ui.model.json.JSONModel();
	    var oTable = t.byId("idTable");

6. The above code inside onUpload event handler will read the data from the CSV file and bind the data to the Table.

You have successfully created a SAPUI5 application to load the data from CSV file. Please stay tuned to us for more SAPUI5 Tutorials.

Comments are closed.