We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to add a Template Excel for multi sheet

I use
Workbook workbook = new Workbook(TempFolder_ + “Template.xls”);

for (int i = 0; i < lstDonVi.Count; i++)
{
Worksheet worksheet = workbook.Worksheets[i];
workbook.Worksheets.Add();
worksheet.Name = lstDonVi[i]//;

}
but only the first sheet is the same template

Hi,

Thanks for your posting and using Aspose.Cells.

Please use the Workbook.Worksheets.AddCopy() method to achieve your requirements. Here is the correct code. I have also attached the output xls file generated by it for your reference.

C#


Workbook workbook = new Workbook(“Template.xls”);

Worksheet worksheet = workbook.Worksheets[0];

//Add 5 copies of worksheet
for (int i = 0; i < 5; i++)
{
int idx = workbook.Worksheets.AddCopy(worksheet.Name);

Worksheet ws = workbook.Worksheets[idx];
ws.Name = worksheet.Name + “-” + i;

}

workbook.Save(“output.xls”);

thank you very much