Skip to Content
author's profile photo Former Member
Former Member

GETTING PROBLEM WHILE UPLOADING DATA FROM EXCEL SHEET TO TABLE IN XML VIEW

Hi Experts,

i want to upload data from excel sheet to table.

Controller Part

onConfirmDialog: function () {

var dialog = new sap.m.Dialog({

title: 'Upload',

type: 'Message',

icon: 'sap-icon://download',

content: [

new sap.ui.unified.FileUploader({

id: 'fileuploader',

width: '100%',

uploadUrl: 'upload/'

})

],

endButton: new sap.m.Button({

text: 'cancel',

press: function () {

dialog.close();

}

}),

beginButton: new sap.m.Button({

text: 'Upload',

press: function csvJSON(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);

}

//return result; //JavaScript object

return JSON.stringify(result); //JSON

}

}),

afterClose: function() {

dialog.destroy();

}

});

dialog.open();

}

Many Thanks,

Ankita Dubey

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Jan 15, 2016 at 07:56 AM

    Hi Ankita ,

    Please try below code .

    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, ""));

    sap.ui.getCore().getModel().setProperty("/", oFinalResult);

    },

    onConfirmDialog: function () {

    var that = this;

    var dialog = new sap.m.Dialog({

    title: 'Upload',

    type: 'Message',

    icon: 'sap-icon://download',

    content: [

    new sap.ui.unified.FileUploader({

    id: 'fileuploader',

    width: '100%',

    uploadUrl: 'upload/',

    change: function(oEvent) {

    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);

    }

    dialog.close();

    }

    })

    ],

    endButton: new sap.m.Button({

    text: 'cancel',

    press: function () {

    dialog.close();

    }

    }),

    afterClose: function() {

    dialog.destroy();

    }

    });

    dialog.open();

    },


    Regards,

    Abhishek Lohiya

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 14, 2016 at 02:21 PM

    Hi Ankita,

    Check this thread: Not able to upload csv sheet and get data in json format and displayed in table.

    Sample: Plunker

    Image Snippet: Imgur

    Regards,

    Sai Vellanki.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.