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 file corrupt on download from express server but works fine on localhost server

See original GitHub issue

So, I’m having this problem that whenever I’m downloading data(json) as .xlsx file its getting corrupted and unusable, this is the case when this app is deployed on heroku using express server. But when I run a local server on my machine and download the file it works just fine and data is there the way I want.

I’m using XLSX version 0.11.3 and on client side only.

Here’s the code:

downloadResData(data) {
    let ws = XLSX.utils.json_to_sheet(data);
    let wb = XLSX.utils.book_new();
    XLSX.utils.book_append_sheet(wb, ws, "data");
    let wbout = XLSX.write(wb, {bookType: 'xlsx', type: 'binary'});

    function s2ab(s) {
      let buf = new ArrayBuffer(s.length);
      let view = new Uint8Array(buf);
      for (let i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
      return buf;
    }

    FileSaver.saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), "data.xlsx");
  }
 }

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
m-ketancommented, Nov 25, 2017

Finally, fixed the issue. The problem was with the browserify package. The version I was using was way too old, I updated it to the latest one and got rid of the corrupted downloads.

0reactions
SheetJSDevcommented, Nov 24, 2017

Copy and paste that string into your application and store it as some variable (like datajson) then hardcode downloadResData(JSON.parse(datajson)) and see if the problem shows up locally.

Read more comments on GitHub >

github_iconTop Results From Across the Web

xlsx file corrupt on download from express server but works ...
So, I'm having this problem that whenever I'm downloading data(json) as .xlsx file its getting corrupted and unusable, this is the case when ......
Read more >
getting corrupt file while trying to download excel(.xlsx) ...
My goal is to send excel (.xlsx) file to the client and download the excel file. Below is my server side code which...
Read more >
IIS 10 corrupts Excel file on download
I have an ASP.Net MVC application that exports data to an Excel workbook; an .xlsx file. The workbook is generated correctly on the...
Read more >
MS Excel corrupt after upload into Azure Blob Storage
Hi Team, I am trying to upload an MS Excel (.xlsx) file via Shared Access Signature (SAS) into a Azure Blob Storage.
Read more >
Express-Server with Netlify functions - Support
My approach on this was: setting up an Express-server (locally tested - it works fine! - result: download of customized xlsx-file as expected);...
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