Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
Xlsx sheetname exceeding 31 characters in length in react

I'm using react to get table data from database and exporting it as excel and making the title of excel as tablename. But I'm facing and issue if the excel file name is exceeding 31 characters, sheet is not getting downloaded. And throwing below error in browser console output.

Uncaught Error: Sheet names cannot exceed 31 chars

Here is my code below

var workbook=XLSX.utils.book_new();
workbook.SheetNames.push(title); //title: tablename
var workSheet=XLSX.utils.aoa_to_sheet(tableData); //tableData: data from Database
workbook.Sheets[title]=workSheet;
var output=XLSX.write(workbook, {bookType:'xlsx', type:'binary'});
function s2ab(s) {
  var buf = new ArrayBuffer(s.length);
  var view = new Uint8Array(buf);
  for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  return buf;
}
saveAs(new Blob([s2ab(output)], {type:"application/octet-stream"}), title + '.xlsx');

Edit: I don't want to change the sheetname. Just wanted react to download even if sheetnames exceeding 31 characters

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Solved by doing following changes

var workbook=XLSX.utils.book_new();
//workbook.SheetNames.push(title); //title: tablename
var workSheet=XLSX.utils.aoa_to_sheet(tableData); //tableData: data from Database
//workbook.Sheets[title]=workSheet;
XLSX.utils.book_append_sheet(workbook, workSheet, "Test"); // This line solve the problem
var output=XLSX.write(workbook, {bookType:'xlsx', type:'binary'});
function s2ab(s) {
  var buf = new ArrayBuffer(s.length);
  var view = new Uint8Array(buf);
  for (var i=0; i!=s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
  return buf;
}
saveAs(new Blob([s2ab(output)], {type:"application/octet-stream"}), title + '.xlsx');
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!