RobertParkinson
asked on
Excel Sheet Name
Hi,
I need to read the sheet name of an excel file using vc++.
Is this possible?
Thanks
I need to read the sheet name of an excel file using vc++.
Is this possible?
Thanks
ASKER
thanks mnashadka,
I am having a little trouble converting the string worksheet_name into anything that i can use though.
it won't convert to a CString and i can not use it in an AfxMessageBox to test to see if it is working.
any ideas?
Thanks
I am having a little trouble converting the string worksheet_name into anything that i can use though.
it won't convert to a CString and i can not use it in an AfxMessageBox to test to see if it is working.
any ideas?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks mnashadka,
That did the trick!
That did the trick!
#include <iostream>
// In the #include area,
// import the type library information
#import "C:\Program Files\Microsoft Office\Office\MSO9.DLL" \
rename("RGB", "OfficeRGB") \
rename("CopyFile", "OfficeCopyFile") \
exclude("DocumentPropertie
no_namespace
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OL
#import "C:\Program Files\Microsoft Office\Office\EXCEL9.OLB" \
rename("DialogBox", "ExcelDialogBox") \
rename("RGB", "ExcelRGB") \
rename("CopyFile", "ExcelCopyFile") \
no_dual_interfaces
// In your function
int main()
{
CoInitialize(NULL); // Initialize COM
try
{
Excel::_ApplicationPtr excel;
HRESULT hr = excel.CreateInstance(L"Exc
Excel::_WorkbookPtr workbook = excel->Workbooks->Open("c:
Excel::_WorksheetPtr worksheet = workbook->Sheets->Item[1l]
std::string worksheet_name = static_cast<char *>(worksheet->Name); // Get the worksheet name
workbook->Close(); // Close the workbook
excel->Quit(); // Quit Excel
}
catch(_com_error &ce)
{
// Error occurred
}
CoUninitialize();
return 0;
}
Good luck!