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.

Excel file not opening on every plateform with Node

See original GitHub issue

Hello, I am currently struggling with opening the file generated by exceljs (v1.7.0) on MS Excel. I can open it but Excel (v16.21.1) says that some styling were not imported and no styling is taken into account. capture d ecran 2019-02-05 a 14 34 12 [EN Traduction] - “Sorry… We found a problem in the file, but we can try to recover as much content as we can. If you trust were the file came from, click yes”

That gives me this Excel that doesn’t take all my styling: capture d ecran 2019-02-05 a 14 47 38

If I try to open the file in the browser with the extension Office Editing for Docs, Sheets & Slides it shows me this error: screenshot 2019-02-05 at 14 29 58

BUT if I manually create a Google spreadsheet and import from there my generated file, the file is correctly displayed and opens correctly: screenshot 2019-02-05 at 14 40 57

And kind of weird, but I generate the file, opens it on Google spreadsheet, download it from there on xlsx format and opens this downloaded file, the file opens correctly. So Google must be doing something I am not. As most of my users will be using Excel, it’s kind of annoying to push them to use Spreadsheet.

Here is the code that I use to generate and style my file

  const workbook = new Excel.Workbook()

  // Worksheet
  const worksheet = workbook.addWorksheet('Detailed capitalization table', {
    pageSetup: { paperSize: 9, orientation: 'landscape', },
  })

  worksheet.views = [
    { state: 'frozen', ySplit: 4, topLeftCell: 'A3', },
    {
      showGridLines: false,
    },
  ]

  // Construction of columns
  // Construction of frozen upper part
  // Put data into columns

And later I do

workbook.xlsx.writeFile('path/to/file.xlsx') // With path to file

I tried without any styling but even then it doesn’t work. Still errors when i try to open the file. Thanks for reading, if you have any lead that would be super helpful!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:30 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
Gildewarz777commented, Apr 5, 2019

Hi, I’ve created a worksheet with nothing on it, but I still get the errors. Here is the code :

  const workbook = await new Excel.Workbook()
  const worksheet = await workbook.addWorksheet('Worksheet')
  workbook.xlsx.writeFile('path/to/file.xlsx') // With path to file

Here is the xml that results from the generated xlsx file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>
<Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>
<Override PartName="/xl/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/>
<Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/>
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/>
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/>
</Types>

And here is the xml when I import the xlsx on Google Spreadsheet and download it in xlsx from there:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default ContentType="application/xml" Extension="xml"/>
<Default ContentType="application/vnd.openxmlformats-package.relationships+xml" Extension="rels"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml" PartName="/xl/worksheets/sheet1.xml"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sharedStrings+xml" PartName="/xl/sharedStrings.xml"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.drawing+xml" PartName="/xl/drawings/drawing1.xml"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml" PartName="/xl/styles.xml"/>
<Override ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml" PartName="/xl/workbook.xml"/>
</Types>

As we can see this line is missing, and might be the cause of the problem:

<Default ContentType="application/xml" Extension="xml"/>
4reactions
flodancommented, Sep 21, 2021

I could fix my problem. For all who stumble upon this issue, maybe the following will help:

  • I had cells with text of a percentage in it (e.g. “50%”). Excel tried to parse them automatically which led to an error. I switched to insert them as a number (e.g. 0.5) and configured it to being displayed as a percentage (0%)
  • I also had a table which I gave a name that had a space in it (e.g. “test table”). It seems that Excel does not allow that (when repairing the file, Excel replaces the space with an underscore)
  • I also used the autoFilter feature on the table, which led to an error. I switched to enabling the filter buttons directly for each column of the table
Read more comments on GitHub >

github_iconTop Results From Across the Web

Opening an excel file with opn while another ... - Stack Overflow
1 Answer 1 · Yeah, Excel seems to spawn a single process for all the files. · I tried it but didn't work....
Read more >
Files do not open in Excel or "File Not Found" occurs when ...
Discusses the "File Not Found" error message that you may receive when you open a file by double-clicking the file name in Excel....
Read more >
How to read and write Excel file in Node.js ? - GeeksforGeeks
Javascript. Explanation: First, the npm module is included in the read. js file and then the excel file is read into a workbook...
Read more >
read-excel-file - npm
const readXlsxFile = require('read-excel-file/node') // File path. readXlsxFile('/path/to/file').then(( ...
Read more >
How to Write Data to An Excel file in NodeJS - Brian Cline
Node is an open source server platform that runs on top of Google Chrome's JavaScript engine called V8. Node includes basically everything ...
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