Sign UpSign Up   Sign InSign In Welcome Guest,
Live Chat Live Chat

How to retrieve the worksheet names

Last post 07-01-2009, 6:42 AM by HJD. 2 replies.
Sort Posts: Previous Next
  •  07-01-2009, 5:55 AM 186334

    How to retrieve the worksheet names .NET

    Attachment: Present (inaccessible)

    Hi,

          How can we retrieve the worksheet names using Aspose.Cells. I have attached below a excel sheet which has three sheets with the names "Test1", "Test2" and "Test3". I was trying the following code snippet -

    workbook = new Workbook();

    workbook.Open(ExcelFileName);

    string[] sNames = new string[workbook.Worksheets.Count];

    Names worksheetNames = workbook.Worksheets.Names;

    foreach (Name name in worksheetNames)

    {

    sNames[loop++] = name.Text;

    }

    return sNames;

    However the collection worksheetNames  did not have any element when I did a quickwatch and so it did not enter the for each loop.

    Please let me know any alternative.

    Thanks

    Hemangajit

     
  •  07-01-2009, 6:19 AM 186338 in reply to 186334

    Re: How to retrieve the worksheet names

    Hi,

    Well, I think you slightly misunderstood Worksheets.Names. Basically it is used to get the collection of defined names (Named ranges defined in the worksheets) in a workbook. You may use Worksheet.Name property to get a worksheet name.

    If you want to get each worksheet name only, you can modify your code a bit.

    workbook = new Workbook();

    workbook.Open(ExcelFileName);

    string[] sNames = new string[workbook.Worksheets.Count];

    int loop = 0;

    foreach (Worksheet sheet in workbook.Worksheets)

    {

    sNames[loop++] = sheet.Name;

    }

    return sNames;

     

     

    For further reference, please check the document:

    http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/managing-worksheets.html

     

    Thank you.


    Amjad Sahi
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
  •  07-01-2009, 6:42 AM 186344 in reply to 186338

    Re: How to retrieve the worksheet names

    Hi Amjad,

                      Thanks a lot. Worked wonder!

     
View as RSS news feed in XML