8000 Corrupted XLSX output due to invalid sheet name · Issue #705 · exceljs/exceljs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Corrupted XLSX output due to invalid sheet name #705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
loreanvictor opened this issue Dec 5, 2018 · 3 comments
Closed

Corrupted XLSX output due to invalid sheet name #705

loreanvictor opened this issue Dec 5, 2018 · 3 comments

Comments

@loreanvictor
Copy link

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.

@Siemienik
Copy link
Member

@loreanvictor you are right,
maybe shall You write pull request with this validation? :)

@omurbekjk
Copy link

@Siemienik Any ideas how to validate correctness of excel? maybe I will try to create pull request.

8000

@Siemienik
Copy link
Member
Siemienik commented Apr 17, 2019

@omurbekjk somethink like that works for me:

       name = name.replace(/[\\\/*\[\]?]/g, '.');  //replace forbidden chars
        if (!scope.isUnique(name))) { //name has to be unique
            name = scope.next(name); // append 1,2,3...
        }        
        name = name.length > 31 ? name.substr(name.length - 31) : name; //max 31 letters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0