question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.xslx file parsing

See original GitHub issue

Hi

I am trying to parse excel file using this js library. I was successfully able to parse xls file. But when i am trying to parse .xlsx file its giving me error. Is their anything else require to be done. Please share.

I am using following code.

 {
            file = input.files[0];
            fr = new FileReader();
            fr.onload=function()
            {
              console.log("loaded");
             
              var content=fr.result;
              if(!rABS) content = new Uint8Array(content);
              var Workbook = XLSX.read(content, { type: 'binary' });
              console.log(Workbook);
              
        Workbook.SheetNames.forEach(function(sheetName) {
		var sheet= Workbook.Sheets[sheetName];	
         var roa = XLSX.utils.sheet_to_json(sheet);
        console.log(roa);
        roa.forEach(function(obj){
               console.log(obj); 
            $("#"+obj.Name).val(obj.Value);
        });

		});
         
            };
            var data= fr.readAsText(file);
         
        }

I am getting following error

Uncaught Error: Cannot find file [Content_Types].xml in zip
    at q (xlsx.full.min.js:12)
    at re (xlsx.full.min.js:12)
    at rv (xlsx.full.min.js:21)
    at sv (xlsx.full.min.js:21)
    at Object.cv [as read] (xlsx.full.min.js:21)
    at FileReader.fr.onload (registration_crud?_mode=edit&id=189_Student_process1:434)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Lathashree01commented, May 12, 2020

readAsBinaryString solved the problem 😃

1reaction
SheetJSDevcommented, Oct 1, 2017

@harminder-emobx-com the problem is in the encoding. readAsText does not work with binary files. You should either be using readAsArrayBuffer or readAsBinaryString. Follow the examples from https://github.com/sheetjs/js-xlsx#parsing-workbooks .

Read more comments on GitHub >

github_iconTop Results From Across the Web

json - How to parse Excel (XLS) file in Javascript/HTML5
Old question, but I should note that the general task of parsing XLS files from javascript is tedious and difficult but not impossible....
Read more >
Parsing Huge XLSX files ins fastest possible way
Apache POI is the most common open source Java library used in the XLSX file parsing but it is very memory intensive, for...
Read more >
Quick'n'dirty solution for parsing XLSX files on the go
Integral parts of the parser · Extract the sheet structure (sheet1.xml) into XSTRING XML · Extract the array of sheet values (sharedStrings.xml) ...
Read more >
Using JavaScript to Work with Spreadsheets, Part 5: Parsing ...
You could certainly use fs.readFile() to read an XLSX file and write code to parse out the data found within. However, this is...
Read more >
Parse and Read Excel Files (xls/xlsx) With JavaScript - Medium
Recently there was a requirement in one of my projects to parse Excel files (with xls/xlsx extensions) in the browser (using javascript ofcourse)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found