How to read excel file in angularjs?












0















I have tried to read excel file to follow the following tutorial.
http://code.psjinx.com/xlsx.js/
But I have failed to read excel file for undefine situation in the following highlighted line.... I have tried it in IE11.



var reader = new FileReader();

reader.onload = function(e) {
var data = e.target.result;
var workbook = XLSX.read(data, {
type: 'binary'
});

obj.sheets = XLSXReader.utils.parseWorkbook(workbook, readCells, toJSON);
handler(obj);
}

**reader.readAsBinaryString(file)**;









share|improve this question























  • Could you specify: are you going to upload your Excel file from desktop or load from server?

    – agershun
    Dec 22 '14 at 15:11
















0















I have tried to read excel file to follow the following tutorial.
http://code.psjinx.com/xlsx.js/
But I have failed to read excel file for undefine situation in the following highlighted line.... I have tried it in IE11.



var reader = new FileReader();

reader.onload = function(e) {
var data = e.target.result;
var workbook = XLSX.read(data, {
type: 'binary'
});

obj.sheets = XLSXReader.utils.parseWorkbook(workbook, readCells, toJSON);
handler(obj);
}

**reader.readAsBinaryString(file)**;









share|improve this question























  • Could you specify: are you going to upload your Excel file from desktop or load from server?

    – agershun
    Dec 22 '14 at 15:11














0












0








0


3






I have tried to read excel file to follow the following tutorial.
http://code.psjinx.com/xlsx.js/
But I have failed to read excel file for undefine situation in the following highlighted line.... I have tried it in IE11.



var reader = new FileReader();

reader.onload = function(e) {
var data = e.target.result;
var workbook = XLSX.read(data, {
type: 'binary'
});

obj.sheets = XLSXReader.utils.parseWorkbook(workbook, readCells, toJSON);
handler(obj);
}

**reader.readAsBinaryString(file)**;









share|improve this question














I have tried to read excel file to follow the following tutorial.
http://code.psjinx.com/xlsx.js/
But I have failed to read excel file for undefine situation in the following highlighted line.... I have tried it in IE11.



var reader = new FileReader();

reader.onload = function(e) {
var data = e.target.result;
var workbook = XLSX.read(data, {
type: 'binary'
});

obj.sheets = XLSXReader.utils.parseWorkbook(workbook, readCells, toJSON);
handler(obj);
}

**reader.readAsBinaryString(file)**;






javascript angularjs excel






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 17 '14 at 10:27









Amin UddinAmin Uddin

46241327




46241327













  • Could you specify: are you going to upload your Excel file from desktop or load from server?

    – agershun
    Dec 22 '14 at 15:11



















  • Could you specify: are you going to upload your Excel file from desktop or load from server?

    – agershun
    Dec 22 '14 at 15:11

















Could you specify: are you going to upload your Excel file from desktop or load from server?

– agershun
Dec 22 '14 at 15:11





Could you specify: are you going to upload your Excel file from desktop or load from server?

– agershun
Dec 22 '14 at 15:11












1 Answer
1






active

oldest

votes


















-1














The following answer describe, if you are going to load xlsx file from server. For uploading there is another code.



OPTION 1: This is a procedure, which works in Alasql library:



See files: 15utility.js and 84from.js for example



readBinaryFile(filename,true,function(a){
var workbook = X.read(data,{type:'binary'});
// do what you need with parsed xlsx
});

// Read Binary reading procedure
// path - path to the file
// asy - true - async / false - sync

var readBinaryFile = utils.loadBinaryFile = function(path, asy, success, error) {
if(typeof exports == 'object') {
// For Node.js
var fs = require('fs');
var data = fs.readFileSync(path);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
success(arr.join(""));
} else {
// For browser
var xhr = new XMLHttpRequest();
xhr.open("GET", path, asy); // Async
xhr.responseType = "arraybuffer";
xhr.onload = function() {
var data = new Uint8Array(xhr.response);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
success(arr.join(""));
};
xhr.send();
};
};


OPTION 2: you can use Alasql library itself, which, probably, can be easier option.



alasql('SELECT * FROM XLSX("myfile.xlsx",{headers:true,sheetid:"Sheet2",range:"A1:D100"})',
,function(data) {
console.log(res);
});


See the example here (simple Excel reading demo) or here (d3.js demo from Excel).






share|improve this answer


























  • can you please provide complete code ?

    – user1121210
    Jun 12 '15 at 2:17











  • X and data are undefined in X.read(data,{type:'binary'})...

    – Aprillion
    Dec 24 '18 at 15:13











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27523406%2fhow-to-read-excel-file-in-angularjs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1














The following answer describe, if you are going to load xlsx file from server. For uploading there is another code.



OPTION 1: This is a procedure, which works in Alasql library:



See files: 15utility.js and 84from.js for example



readBinaryFile(filename,true,function(a){
var workbook = X.read(data,{type:'binary'});
// do what you need with parsed xlsx
});

// Read Binary reading procedure
// path - path to the file
// asy - true - async / false - sync

var readBinaryFile = utils.loadBinaryFile = function(path, asy, success, error) {
if(typeof exports == 'object') {
// For Node.js
var fs = require('fs');
var data = fs.readFileSync(path);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
success(arr.join(""));
} else {
// For browser
var xhr = new XMLHttpRequest();
xhr.open("GET", path, asy); // Async
xhr.responseType = "arraybuffer";
xhr.onload = function() {
var data = new Uint8Array(xhr.response);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
success(arr.join(""));
};
xhr.send();
};
};


OPTION 2: you can use Alasql library itself, which, probably, can be easier option.



alasql('SELECT * FROM XLSX("myfile.xlsx",{headers:true,sheetid:"Sheet2",range:"A1:D100"})',
,function(data) {
console.log(res);
});


See the example here (simple Excel reading demo) or here (d3.js demo from Excel).






share|improve this answer


























  • can you please provide complete code ?

    – user1121210
    Jun 12 '15 at 2:17











  • X and data are undefined in X.read(data,{type:'binary'})...

    – Aprillion
    Dec 24 '18 at 15:13
















-1














The following answer describe, if you are going to load xlsx file from server. For uploading there is another code.



OPTION 1: This is a procedure, which works in Alasql library:



See files: 15utility.js and 84from.js for example



readBinaryFile(filename,true,function(a){
var workbook = X.read(data,{type:'binary'});
// do what you need with parsed xlsx
});

// Read Binary reading procedure
// path - path to the file
// asy - true - async / false - sync

var readBinaryFile = utils.loadBinaryFile = function(path, asy, success, error) {
if(typeof exports == 'object') {
// For Node.js
var fs = require('fs');
var data = fs.readFileSync(path);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
success(arr.join(""));
} else {
// For browser
var xhr = new XMLHttpRequest();
xhr.open("GET", path, asy); // Async
xhr.responseType = "arraybuffer";
xhr.onload = function() {
var data = new Uint8Array(xhr.response);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
success(arr.join(""));
};
xhr.send();
};
};


OPTION 2: you can use Alasql library itself, which, probably, can be easier option.



alasql('SELECT * FROM XLSX("myfile.xlsx",{headers:true,sheetid:"Sheet2",range:"A1:D100"})',
,function(data) {
console.log(res);
});


See the example here (simple Excel reading demo) or here (d3.js demo from Excel).






share|improve this answer


























  • can you please provide complete code ?

    – user1121210
    Jun 12 '15 at 2:17











  • X and data are undefined in X.read(data,{type:'binary'})...

    – Aprillion
    Dec 24 '18 at 15:13














-1












-1








-1







The following answer describe, if you are going to load xlsx file from server. For uploading there is another code.



OPTION 1: This is a procedure, which works in Alasql library:



See files: 15utility.js and 84from.js for example



readBinaryFile(filename,true,function(a){
var workbook = X.read(data,{type:'binary'});
// do what you need with parsed xlsx
});

// Read Binary reading procedure
// path - path to the file
// asy - true - async / false - sync

var readBinaryFile = utils.loadBinaryFile = function(path, asy, success, error) {
if(typeof exports == 'object') {
// For Node.js
var fs = require('fs');
var data = fs.readFileSync(path);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
success(arr.join(""));
} else {
// For browser
var xhr = new XMLHttpRequest();
xhr.open("GET", path, asy); // Async
xhr.responseType = "arraybuffer";
xhr.onload = function() {
var data = new Uint8Array(xhr.response);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
success(arr.join(""));
};
xhr.send();
};
};


OPTION 2: you can use Alasql library itself, which, probably, can be easier option.



alasql('SELECT * FROM XLSX("myfile.xlsx",{headers:true,sheetid:"Sheet2",range:"A1:D100"})',
,function(data) {
console.log(res);
});


See the example here (simple Excel reading demo) or here (d3.js demo from Excel).






share|improve this answer















The following answer describe, if you are going to load xlsx file from server. For uploading there is another code.



OPTION 1: This is a procedure, which works in Alasql library:



See files: 15utility.js and 84from.js for example



readBinaryFile(filename,true,function(a){
var workbook = X.read(data,{type:'binary'});
// do what you need with parsed xlsx
});

// Read Binary reading procedure
// path - path to the file
// asy - true - async / false - sync

var readBinaryFile = utils.loadBinaryFile = function(path, asy, success, error) {
if(typeof exports == 'object') {
// For Node.js
var fs = require('fs');
var data = fs.readFileSync(path);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
success(arr.join(""));
} else {
// For browser
var xhr = new XMLHttpRequest();
xhr.open("GET", path, asy); // Async
xhr.responseType = "arraybuffer";
xhr.onload = function() {
var data = new Uint8Array(xhr.response);
var arr = new Array();
for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
success(arr.join(""));
};
xhr.send();
};
};


OPTION 2: you can use Alasql library itself, which, probably, can be easier option.



alasql('SELECT * FROM XLSX("myfile.xlsx",{headers:true,sheetid:"Sheet2",range:"A1:D100"})',
,function(data) {
console.log(res);
});


See the example here (simple Excel reading demo) or here (d3.js demo from Excel).







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 22 '14 at 15:12

























answered Dec 22 '14 at 8:35









agershunagershun

2,9371833




2,9371833













  • can you please provide complete code ?

    – user1121210
    Jun 12 '15 at 2:17











  • X and data are undefined in X.read(data,{type:'binary'})...

    – Aprillion
    Dec 24 '18 at 15:13



















  • can you please provide complete code ?

    – user1121210
    Jun 12 '15 at 2:17











  • X and data are undefined in X.read(data,{type:'binary'})...

    – Aprillion
    Dec 24 '18 at 15:13

















can you please provide complete code ?

– user1121210
Jun 12 '15 at 2:17





can you please provide complete code ?

– user1121210
Jun 12 '15 at 2:17













X and data are undefined in X.read(data,{type:'binary'})...

– Aprillion
Dec 24 '18 at 15:13





X and data are undefined in X.read(data,{type:'binary'})...

– Aprillion
Dec 24 '18 at 15:13




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f27523406%2fhow-to-read-excel-file-in-angularjs%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python