cancel
Showing results for 
Search instead for 
Did you mean: 

Read the data from CSV File

former_member225463
Participant
0 Kudos

Hello Experts,

In my project i came  across a requirement where there are lots of records in a CSV file and i have to create all the records using Batch Operation upon clicking the upload button.

Can you please help me how to read the data of the file in the runtime , what i feel is that i have to know the url of my local file first and then read the file data using AJAX but am not getting any clue for how to get the url of the file during run time.

Please help me in this.Thanks in advance.

Regards,

Vikash

Accepted Solutions (0)

Answers (1)

Answers (1)

karthikarjun
Active Contributor

Hi Vikash,

<FileUploader xmlns="sap.ui.unified" 

  uploadUrl="" 

  buttonText="{i18n>detailBtnImport}" 

  fileType="csv" 

  maximumFileSize="1" 

  buttonOnly="true" 

  icon="sap-icon://upload" 

  change="onChangeFUP" 

  uploadComplete="onUploadCompleteFUP" 

  typeMissmatch="onFailedFUP" 

  fileSizeExceed="onFailedFUP" 

  uploadAborted="onFailedFUP" 

  filenameLengthExceed="onFailedFUP"/> 

onChangeFUP : function(e) { 

  this._import(e.getParameter("files") && e.getParameter("files")[0]); 

}, 

_import : function(file) { 

  if(file && window.FileReader){ 

  var reader = new FileReader(); 

  var that = this

  reader.onload = function(e) { 

  var strCSV= e.target.result; //string in CSV 

  };reader.readAsText(file); 

Refer from :

@Raman Sharapinski Comment.

var strCSV= e.target.result; //string in CSV - Here you will get your csv file records



Thanks,

Karthik A

former_member225463
Participant
0 Kudos

Hi Karthik,

Thanks for the reply.The Import Function which you mentioned that should trigger when i click on upload button right?or this should be triggered in some event of file uploader.

Please let me know so i can proceed with it.

Regards,

Vikash