Egor Kraev's Homepage
  Getting the Excel Driver to work
Book Home
Code
VC++ 2003
Typos
FAQ
 
  The Excel Driver is perhaps the part of the code with the most quirks. Here is a collection of suggestions to make it work, based on comments by Dr. Duffy and (successful) experimentation by Dr. Egor Kraev.

1. Get the right version of the Excel Driver

There are several included on the book CD. If you have Office 2000 or earlier, use the one called ExcelDriver.cpp in the PDEFDM directory. If you have Office XP or Office 2003, use this version (fixed by Martin Nisbit; the version on the CD gives a "type mismatch" error at runtime for these Office versions, see discussion here)

2. Import the right libraries

There are three libraries needed to make Excel driver run; you will need to give the right path to them both in ExcelDriver.cpp and Imports.hpp. The exact location of the libraries on your computer may vary, but below is a good first guess:

// Import necessary typelib's for Excel

// Office 97 (Office v8)
//#import "d:\program files\microsoft office\office\mso97.dll" no_namespace rename("DocumentProperties", "DocumentPropertiesXL")
//#import "d:\program files\common files\microsoft shared\vba\vbeext1.olb" no_namespace
//#import "d:\program files\microsoft office\office\Excel8.olb" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces

// Office 2000 (Office v9)
//#import "C:\Program Files\Microsoft Office\Office\mso9.dll" no_namespace rename("DocumentProperties", "DocumentPropertiesXL")
//#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb" no_namespace
//#import "C:\Program Files\Microsoft Office\Office\Excel9.olb" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces

// Office XP (2002) (Office v10)
//#import "C:\Program Files\Common Files\Microsoft Shared\office10\mso.dll" rename("DocumentProperties", "DocumentPropertiesXL") rename("RGB", "RBGXL")
//#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb"
//#import "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") rename("ReplaceText", "ReplaceTextXL") rename("CopyFile", "CopyFileXL") no_dual_interfaces

// Office 2003 (Office v11) (Will give error (actually a warning) that you need W2K or higher to run the result)
#import "C:\Program Files\Common Files\Microsoft Shared\office11\mso.dll" rename("DocumentProperties", "DocumentPropertiesXL") rename("RGB", "RBGXL")
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\vbe6ext.olb"
#import "C:\Program Files\Microsoft Office\Office11\EXCEL.EXE" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") rename("ReplaceText", "ReplaceTextXL") rename("CopyFile", "CopyFileXL") no_dual_interfaces

3. Include the right search paths

In particular, Imports.hpp must be visible. If you're compiling any code from the book, chances are you'll also need to include at least VectorsAndMatrices and PropertyPattern

4. If using Visual C++ 2003 or Dev-C++ , adjust PropertyPattern source code

See here for explanation and modified source.

5. Use Vector<double, long> instead of Vector<double, int> to pass data to Excel

In particular in Chapter 22, all examples use Vector<double, int> to store data vectors. However, the Excel driver chokes on these, but works happily if you change them to Vector<double, long> . This could probably be eliminated by making sure Vector<V,I> always has a constructor that takes Vector<V,int> - if EK succeeds at that, will post source code here.

A sample file that compiles with VC++ 2003 is forthcoming.