0
let workbook = new Excel.Workbook();
for (let i = 0; i < 3; i++){
    workbook.addWorksheet('test', {
      properties: {tabColor: {argb: 'FF00FF00'}}, views: [
        {ySplit: 5, activeCell: 'A1', showGridLines: false}
      ]
    });
  }

First worksheet will have 'test' name, others will have an error title. Do you know how to make it work?

EDIT : If i generate my worksheet in a function, it works.

let workbook = new Excel.Workbook();

function generateWorksheet(data){
workbook.addWorksheet('test', {
    properties: {tabColor: {argb: 'FF00FF00'}}, views: [
         {ySplit: 5, activeCell: 'A1', showGridLines: false}
    ]
   });
  }
  for (let i = 0; i < 3; i++){
     generateWorksheet(i);
  }
So4ne
  • 1,124
  • 17
  • 38

1 Answers1

0

I think the issue is that you can't create multiple worksheets with the same name. So append the loop index to each worksheet.

let workbook = new Excel.Workbook();
for (let i = 0; i < 3; i++){
    workbook.addWorksheet('test'+i, {
      properties: {tabColor: {argb: 'FF00FF00'}}, views: [
        {ySplit: 5, activeCell: 'A1', showGridLines: false}
      ]
    });
 }

So now the worksheet name would be test plus the loop index.

Ashwin Kumar
  • 1,228
  • 7
  • 24
  • 1
    Nope, I saw the source code, even though this might work but addWorkSheet creates a `new WorkSheet` object and adds the name there. The objects are independant to each other. there is no name check whatsoever. – Aritra Chakraborty Aug 08 '18 at 17:23
  • Thanks for your answer but as @AritraChakraborty said I tried with dynamic name based on index and that didn't work either. – So4ne Aug 09 '18 at 07:22