You need to perform three basic operations.
1) Make sure the preinstall files are installed and localized.
It is dazzlingly obvious that I know, but make sure you have the right version of Excel installed so that you can find the necessary Microsoft libraries (and their locations). namely MSO.DLL, VBE6EXT.OLB and EXCEL.EXE
2) Configure Microsoft libraries.
In your C ++ code, let's say you start with a simple console application, be sure to include import libraries in any C ++ application that interacts with Excel. In my example, I use:
#import "C:\\Program Files (x86)\\Common Files\\microsoft shared\\OFFICE11\\MSO.DLL" \ rename( "RGB", "MSORGB" ) using namespace Office; #import "C:\\Program Files (x86)\\Common Files\\microsoft shared\\VBA\\VBA6\\VBE6EXT.OLB" using namespace VBIDE; #import "C:\\Program Files (x86)\\Microsoft Office\\OFFICE11\\EXCEL.EXE" \ rename( "DialogBox", "ExcelDialogBox" ) \ rename( "RGB", "ExcelRGB" ) \ rename( "CopyFile", "ExcelCopyFile" ) \ rename( "ReplaceText", "ExcelReplaceText" ) \ exclude( "IFont", "IPicture" ) no_dual_interfaces
3) Use the Excel object model in C ++ code
For example, to declare a pointer to an Excel application object for reading / writing an Excel workbook:
Excel::_ApplicationPtr pXL; pXL->Workbooks->Open( L"C:\\dump\\book.xls" );
And to access and manage the Excel worksheet and its cells:
Excel::_WorksheetPtr pWksheet = pXL->ActiveSheet; Excel::RangePtr pRange = pWksheet->Cells; double value = pRange->Item[1][1]; pRange->Item[1][1] = 5.4321;
And so on. I have a more detailed discussion on my next blog post .