locked
How to get the list of worksheet names using C++ RRS feed

  • Question

  • I am new to C++, before I was using C#.

    Developing an application, where in I need to get all Excel workbook and worksheet names.

    I am using following imports:

    //Mircorsoft Office Objects
    #import \
         "C:\Program Files (x86)\Common Files\Microsoft Shared\OFFICE12\mso.dll"\
         rename("DocumentProperties", "DocumentPropertiesXL")\
         rename("RGB", "RBGXL")

    //Microsoft VBA Objects
    #import \
         "C:\Program Files (x86)\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb"

    //Excel Application Objects

    using namespace Office;

    #import "C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE"\
         rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL")\
         rename("DocumentProperties", "DocumentPropertiesXL")\
         rename("ReplaceText", "ReplaceTextXL")\
         rename("CopyFile", "CopyFileXL")\
         exclude("IFont", "IPicture") no_dual_interfaces


    Excel::_ApplicationPtr XL;
    Excel::_WorkbookPtr book;
    Excel::_WorksheetPtr sheet;

    By using for loop ,able to get all workbook names.Using following code iterating through item, getting all workbook names.

    book = XL->Workbooks->Item[1];

    string  BookName = book->Name;

    In case of worksheet, i am not getting the name of worksheet.There is no such option as workbook.

    Able to point to particular sheet:
    sheet = XL->Workbooks->Item[1]->Sheets->Item[1];

    Name and Names option is there but how to retrieve the names of excel sheets using these.

    I want to retrieve whole list of worksheets present in workbook.

    Googled but I didn't get any clue, checked all other excel automation queries in msdn but there is no clue.

    If there is any option, please give me clue.

    Thanks in advance.

    Gtag.
    Friday, October 2, 2009 2:00 PM

Answers

  • [...]

    Able to point to particular sheet:
    sheet = XL->Workbooks->Item[1]->Sheets->Item[1];

    Name and Names option is there but how to retrieve the names of excel sheets using these.

    [...]

    This gives the name of the worksheet:

     

        _bstr_t name = sheet->Name;

     

     

    • Marked as answer by Nancy Shao Monday, October 12, 2009 2:25 AM
    Saturday, October 3, 2009 1:12 PM

All replies

  • If you don't get any nibbles here, you might try the Microsoft Discussion Groups.

    Go to the main page and drill down:

    http://www.microsoft.com/communities/newsgroups/en-us/default.aspx

    Follow the path of:

    English->Developer Discussions->Office Developer->Excel->Excel Programming

    or

    English->Developer Discussions->Office Developer->Office Development General->Office Developer Automation


    - Wayne
    Saturday, October 3, 2009 7:46 AM
  • [...]

    Able to point to particular sheet:
    sheet = XL->Workbooks->Item[1]->Sheets->Item[1];

    Name and Names option is there but how to retrieve the names of excel sheets using these.

    [...]

    This gives the name of the worksheet:

     

        _bstr_t name = sheet->Name;

     

     

    • Marked as answer by Nancy Shao Monday, October 12, 2009 2:25 AM
    Saturday, October 3, 2009 1:12 PM