How to get list of worksheet names using VC++ [modified]
-
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]; 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, but name option is not there. sheet = XL->Workbooks->Item[1]->Sheets->Item[1]; I want to retrieve whole list of worksheets present in workbook. Googled but I didn't get any clue. If there is any option, please give me clue. Thanks in advance. Gtag. Hey if any one knows, please give me clue.
modified on Tuesday, September 29, 2009 9:29 AM
-
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]; 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, but name option is not there. sheet = XL->Workbooks->Item[1]->Sheets->Item[1]; I want to retrieve whole list of worksheets present in workbook. Googled but I didn't get any clue. If there is any option, please give me clue. Thanks in advance. Gtag. Hey if any one knows, please give me clue.
modified on Tuesday, September 29, 2009 9:29 AM
// --- Print worksheet names Excel::_WorksheetPtr p_sheet; m_lngWorksheets = m_xLBook->Worksheets->Count; TRACE("Number of Worksheets is <%d>\n", m_lngWorksheets ); for ( ico=1;ico<=m_lngWorksheets;ico++ ) { p_sheet = m_xLBook->Worksheets->Item[ico]; _stprintf(p_szBuffer, _T("%s"), (LPCTSTR)p_sheet->Name); TRACE("Worksheet %d Name is %s\n", ico, p_szBuffer ); }