Skip to content

Corrupted XLSX output due to invalid sheet name #705

Closed
@loreanvictor

Description

@loreanvictor

So I noticed that while some softwares could open generated XLSX files using exceljs (like Numbers on MacOS and Google Sheets), Microsoft Excel (or Excel Online) was unable to open the files, giving me an error indicating that the file is corrupted. After simplifying the code and isolating the issue, I realized that for some reason MS Excel assumes a maximum length of 31 characters for Worksheet titles and as a result was deeming the generated file corrupt.

So basically, this snippet works fine:

const excel = require('exceljs');

let book = new excel.Workbook();
let sheet = book.addWorksheet('random sheet name that is valid');

sheet.columns = [
  {header: 'First Name', key: 'firstName'},
  {header: 'Last Name', key: 'lastName'}
];

sheet.addRow({ firstName: 'John', lastName: 'Wick' });
sheet.addRow({ firstName: 'Elliot', lastName: 'Alderson'});

book.xlsx.writeFile('test.xlsx');

While this one doesn't:

const excel = require('exceljs');

let book = new excel.Workbook();
let sheet = book.addWorksheet('random sheet name that is not valid');

sheet.columns = [
  {header: 'First Name', key: 'firstName'},
  {header: 'Last Name', key: 'lastName'}
];

sheet.addRow({ firstName: 'John', lastName: 'Wick' });
sheet.addRow({ firstName: 'Elliot', lastName: 'Alderson'});

book.xlsx.writeFile('test.xlsx');

Since MS Excel is what most end-users will use to open automatically generated files by a web-service, I would highly recommend adding an error/warning message for when this case occurs, a toggle-able validation that is on by default, or at least a hint to the documentation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy