Free Support Forum - aspose.com

Worksheet name

I add many sheets with this code:

this.excel.Worksheets.Clear();
for(int j=0; j<names.Length; j++)
{
this.sheet = this.excel.Worksheets[this.excel.Worksheets.Add()];
this.sheet.Name = names[j];
}


In some cases I become exception: “The same worksheet name already exists”.
But all names are unique. What can it be?

Thanks

When Worksheets.Add() method is called, a preset name is assigned to this sheet. Typically it’s “Sheet1”, “Sheet2”,…

If the name in your name array is same as those names, exception will be thrown. Please check it.

No each sheet will be renamed with unique name.

How long can be the name? Maybe long names are the problem…

Thanks

Yes. Maybe the long names caused the problem. The max length of worksheet is 31. This is a limitation of MS Excel.
Aspose.Excel trims the extra string. So that may cause your problem. And the sheet name is case insensitive. For example, you cannot set “SheetName1” to the first worksheet and set “SHEETNAME1” to the second worksheet.