admin管理员组文章数量:1401134
I'm using SheetJS in order to parse Excel sheets however I run into the following error:
"Uncaught TypeError: jszip is not a function"
When executing the following code:
var url = "/test-files/test.xlsx";
var oReq = new XMLHttpRequest();
oReq.open("GET", url, true);
oReq.responseType = "arraybuffer";
oReq.onload = function(e) {
var arraybuffer = oReq.response;
var data = new Uint8Array(arraybuffer);
var arr = new Array();
for(var i = 0; i != data.length; i++) arr[i] = String.fromCharCode(data[i]);
var bstr = arr.join("");
var workbook = XLSX.read(bstr, {type: "binary"});
}
oReq.send();
The original code is located here:
Are there any suggestions for an easier implementation of parsing Excel files?
I'm using SheetJS in order to parse Excel sheets however I run into the following error:
"Uncaught TypeError: jszip is not a function"
When executing the following code:
var url = "/test-files/test.xlsx";
var oReq = new XMLHttpRequest();
oReq.open("GET", url, true);
oReq.responseType = "arraybuffer";
oReq.onload = function(e) {
var arraybuffer = oReq.response;
var data = new Uint8Array(arraybuffer);
var arr = new Array();
for(var i = 0; i != data.length; i++) arr[i] = String.fromCharCode(data[i]);
var bstr = arr.join("");
var workbook = XLSX.read(bstr, {type: "binary"});
}
oReq.send();
The original code is located here: https://github./SheetJS/js-xlsx
Are there any suggestions for an easier implementation of parsing Excel files?
Share Improve this question edited Aug 4, 2015 at 22:22 yvesmancera 2,9255 gold badges26 silver badges33 bronze badges asked Aug 4, 2015 at 22:09 Geno DiazGeno Diaz 5101 gold badge8 silver badges21 bronze badges 6- Looks like you're missing the jszip dependency on your project. Are you using the dist version of js-xlsx? – yvesmancera Commented Aug 4, 2015 at 22:15
- Sorry what do you mean by "dist"? – Geno Diaz Commented Aug 4, 2015 at 22:16
- 1 The distribution version of xlsx.js. How did you include the script in your project? According to their bower.json, js-xlsx has no dependencies, and the file you should be using is located in dist/xlsx.js. – yvesmancera Commented Aug 4, 2015 at 22:17
- O my god! Well there goes 2 hours of running around in circles. Thanks @yvesmancera. For the sake of my sanity do you mind explaining the logic behind your leading to that conclusion. I'm REALLY new into this type of programming and I want to learn the mindset of finding the root of these types of errors. – Geno Diaz Commented Aug 4, 2015 at 22:21
- 1 Sure, first I looked at the GitHub project and read the Installation section, then I saw the project's source files, more specifically, their bower.json file, which indicates what the main file and which dependencies it has, since I saw it had no dependencies, I assumed you must have included the file xlsx.js located in src instead of the one located in dist. – yvesmancera Commented Aug 4, 2015 at 22:25
2 Answers
Reset to default 5Posting as answer(solution provided in ments worked) in case this might help someone else in the future:
It looks like you're using the src/xlsx.js version of xlsx.js, which is dependent on other source files, like jszip.js.
To fix this, use the dist version of xlsx.js located in dist/xlsx.js
Here is another solution for people who have problem when trying to use Excel file in JavaScript.Instead of reading an Excel file with JavaScript, you could directly use JavaScript in Excel with the help of the Funfun Excel add-in. Basically, Funfun is a tool that allows you to use JavaScript in Excel, therefore you don't need to use write additional code to parse Excel files.
Basically, what you need to do is
1). Insert the Funfun add-in from Office Add-ins store
2). Create a new Funfun or load a sample from Funfun online editor
3). Write JavaScrip code as you do in any other JavaScript editor. In this step, in order to directly use the data from the spreadsheet, you need to write some JSON I/O to make Excel cell reference. The place this value is in Setting-short but this would be just several lines. For example, let's assume we have some data like below in the spreadsheet.
In this case, the JSON I/O value would be:
{
"data": "=A1:E9"
}
Then in the script.js file, you just need to use one single line of code to read this data.
var dataset = $internal.data;
The dataset would be an array, each item would be one row in the spreadsheet. You could check the Funfun documentation for more explanation.
4). Run the code to plot chart
Here is a sample chart that I made using JavaScript(HighChart.js) and Excel data on Funfun online editor. You could check it on the link below. You could also easily load it to your Excel as described in Step2.
https://www.funfun.io/1/edit/5a439b96b848f771fbcdedf0
Disclosure: I'm a developer from Funfun.
本文标签: Parsing Excel sheet using javascriptStack Overflow
版权声明:本文标题:Parsing Excel sheet using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744303525a2599698.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论