Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda