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.

XLSX.read is not a function Electron JS

See original GitHub issue

Dears, I’m fairly new to this thing, so let me know what info I’m missing: VSCode Electron 11 Trying to read a local excel file in browser.

What I tried:

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.16.9/xlsx.core.min.js"></script>

AND (not simultaneously)

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.16.9/xlsx.full.min.js"></script>

What happened: I wrote the html file, and opened it in chrome (87.0 64bit, latest as of 2021-jan-03) It worked fine, reading alright. Then I npm-started the project in VSCode, and I got: “Uncaught TypeError: XLSX.read is not a function at FileReader.filereader.onload”

My Code Snippet:

`<script type="text/javascript">

    let resultingJSON;
    function selectFile() 
    {
        let selectedFile;
        document.getElementById('file').click();
        document.getElementById('file').addEventListener('change', function (e)
        {
            selectedFile = e.target.files[0];
            var fileReader = new FileReader();
            fileReader.readAsBinaryString(selectedFile);
            fileReader.onload = (event)=>
            {                
                let data = event.target.result;
                let workbook = XLSX.read(data,{type:"binary"});
                let workSheet = workbook.Sheets["Sheet1"];
                resultingJSON = XLSX.utils.sheet_to_json(workSheet);
            }
        });
    }
</script>`

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fujinxiangcommented, Sep 10, 2021

if nodeIntegration = true,window.module is not undefined,xlsx use CommonJs, so window.XLSX = {}

there is source code from xlsx

if(typeof exports !== 'undefined') make_xlsx_lib(exports);
else if(typeof module !== 'undefined' && module.exports) make_xlsx_lib(module.exports);
else if(typeof define === 'function' && define.amd) define(function() { if(!XLSX.version) make_xlsx_lib(XLSX); return XLSX; });
else make_xlsx_lib(XLSX);

maybe you can find an answer: https://juejin.cn/post/7006212507719172127/

0reactions
SheetJSDevcommented, Sep 10, 2021

Please try using the require form. You can see how the demo does it by using a script tag to reference the JS file and performing a require from the script

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use the xlsx.readFile function in xlsx - Snyk
it('should detect a sheet marked as a boxed context without result', function() { var workbook = XLSX.readFile(testDataFile2); var worksheet = workbook.Sheets[" ...
Read more >
SheetJS read excel file, my file is not read - Stack Overflow
So I am trying to use the SheetJS javascript to read in some excel files. I download the SheetJS and I have copied...
Read more >
Developers - XLSX.read is not a function Electron JS - - Bountysource
Dears, I'm fairly new to this thing, so let me know what info I'm missing: VSCode. Electron 11. Trying to read a local...
Read more >
Electron 中XLSX.read is not a function 的原因 - 掘金
在XLSX 的Github 官网发现一个issue XLSX.read is not a function Electron JS · Issue #2209 · SheetJS/sheetjs,但是并没有解决问题。
Read more >
Data Import | SheetJS Community Edition
Browsers generally do not allow reading files by specifying filename (it is a security risk), and running XLSX.readFile in the browser will throw...
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