Duplicate Worksheet Name

Hello,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Is there anyway that I can check for the existence of worksheet (by name) prior to creating a new worksheet?

Thanks.

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please use Worksheet.Name property to get the worksheet name.

You can use foreach loop for this purpose.

Please see the code below.

C#


foreach (Worksheet ws in workbook.Worksheets)

{

if (ws.Name == yourName)

break;

}



Thanks unfortunately this does not work as the worksheet is still being created at this point.

Hi,

Here is another way.

C#


if(workbook.Worksheets[“yourSheetName”]==null)
{

//sheet does not exist, so you can create this sheet.

}