Excel类型库

场景:VC++ 导入Excel类型库的有关问题?

VC++ 导入Excel类型库的问题??
VS 2005 + sp1 MFC 工程

在新建立的 Dlg程序中,添加-》类-》typelib MFC类-》选择注册-》Excel

添加了如下几个库:_Application, _Workbook, Workbooks, Worksheets,_Wroksheet,Range等几个常用的类

列举其中一个类:
C/C++ code

#import "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE" no_namespace
// CApplication 包装类

class CApplication : public COleDispatchDriver
{
public:
    CApplication(){} // 调用 COleDispatchDriver 默认构造函数
    CApplication(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
    CApplication(const CApplication& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}

    // 属性
public:

    // 操作
public:


    // _Application 方法
public:
    LPDISPATCH get_Application()
    {
        LPDISPATCH result;
        InvokeHelper(0x94, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
        return result;
    }
    long get_Creator()
    {
        long result;
        InvokeHelper(0x95, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
        return result;
    }
。。。。。。



每一个类都是这样,只有.h文件,没有cpp文件。在编译时,报了N多错误!!

C/C++ code
1>CExcelDlg.cpp
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1219) : error C2371: “FontPtr”: 重定义;不同的基类型
1>        c:\program files\microsoft visual studio 8\vc\include\comdef.h(322) : 参见“FontPtr”的声明
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1297) : error C2786: “BOOL (__stdcall *)(HDC,int,int,int,int)”: __uuidof 的操作数无效
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1297) : error C2923: “_com_IIID”:“Rectangle”不是参数“_Interface”的有效 模板 类型变量
1>        c:\program files\microsoft visual studio 8\vc\platformsdk\include\wingdi.h(3514) : 参见“Rectangle”的声明
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1297) : error C3203: “_com_IIID”: 未专用化的类 模板 不能用作 模板 变量,该变量属于 模板 参数“_IIID”,应为 real 类型
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1301) : error C2786: “BOOL (__stdcall *)(HDC,int,int,int,int,int,int,int,int)”: __uuidof 的操作数无效
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1301) : error C2923: “_com_IIID”:“Arc”不是参数“_Interface”的有效 模板 类型变量
1>        c:\program files\microsoft visual studio 8\vc\platformsdk\include\wingdi.h(2765) : 参见“Arc”的声明
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1301) : error C3203: “_com_IIID”: 未专用化的类 模板 不能用作 模板 变量,该变量属于 模板 参数“_IIID”,应为 real 类型
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1308) : error C2371: “PicturePtr”: 重定义;不同的基类型
1>        c:\program files\microsoft visual studio 8\vc\include\comdef.h(336) : 参见“PicturePtr”的声明
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1689) : error C2504: “_IMsoDispObj”: 未定义基类
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1731) : error C2504: “_IMsoDispObj”: 未定义基类
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1833) : error C2504: “_IMsoDispObj”: 未定义基类
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1852) : error C2146: 语法错误 : 缺少“;”(在标识符“GetRGB”的前面)
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1852) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1852) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1852) : warning C4183: “GetRGB”: 缺少返回类型;假定为返回“int”的成员函数
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1854) : error C2061: 语法错误 : 标识符“MsoRGBType”
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1870) : error C2061: 语法错误 : 标识符“MsoRGBType”
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1872) : error C2061: 语法错误 : 标识符“MsoRGBType”
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(1887) : error C2504: “_IMsoDispObj”: 未定义基类
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2017) : error C2504: “_IMsoDispObj”: 未定义基类
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2056) : error C2504: “_IMsoDispObj”: 未定义基类
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2139) : error C2504: “_IMsoDispObj”: 未定义基类
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2189) : error C2146: 语法错误 : 缺少“;”(在标识符“GetTransparencyColor”的前面)
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2189) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2189) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2189) : warning C4183: “GetTransparencyColor”: 缺少返回类型;假定为返回“int”的成员函数
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2191) : error C2061: 语法错误 : 标识符“MsoRGBType”
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2235) : error C2061: 语法错误 : 标识符“MsoRGBType”
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2237) : error C2061: 语法错误 : 标识符“MsoRGBType”
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2246) : error C2504: “_IMsoDispObj”: 未定义基类
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2335) : error C2504: “_IMsoDispObj”: 未定义基类
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2453) : error C2504: “_IMsoDispObj”: 未定义基类
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(2579) : error C2504: “_IMsoDispObj”: 未定义基类
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(5491) : error C2011: “Font”: “struct”类型重定义
1>        c:\program files\microsoft visual studio 8\vc\include\comdef.h(320) : 参见“Font”的声明
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(7783) : warning C4003: “DialogBoxW”宏的实参不足
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(7783) : error C2059: 语法错误 : “,”
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(17141) : error C2011: “Picture”: “struct”类型重定义
1>        c:\program files\microsoft visual studio 8\vc\include\comdef.h(334) : 参见“Picture”的声明
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18104) : error C2146: 语法错误 : 缺少“;”(在标识符“Scripts”的前面)
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18104) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18104) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18150) : error C2146: 语法错误 : 缺少“;”(在标识符“MailEnvelope”的前面)
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18150) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18150) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18355) : error C2146: 语法错误 : 缺少“;”(在标识符“GetScripts”的前面)
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18355) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18355) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18355) : warning C4183: “GetScripts”: 缺少返回类型;假定为返回“int”的成员函数
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18373) : error C2146: 语法错误 : 缺少“;”(在标识符“GetMailEnvelope”的前面)
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18373) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18373) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(18373) : warning C4183: “GetMailEnvelope”: 缺少返回类型;假定为返回“int”的成员函数
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(23176) : error C2146: 语法错误 : 缺少“;”(在标识符“Script”的前面)
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(23176) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(23176) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(23202) : error C2146: 语法错误 : 缺少“;”(在标识符“CanvasItems”的前面)
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(23202) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(23202) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(23381) : error C2146: 语法错误 : 缺少“;”(在标识符“GetScript”的前面)
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(23381) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(23381) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\vs05\cexceldlg\cexceldlg\debug\excel.tlh(23381) : warning C4183: “GetScript”: 缺少返回类型;假定为返回

不知道为啥,用系统导入的MFC类。竟然不能使用。。

大家谁知道这样的问题,应该如何解决哪???诚心求教!!!!


------解决方案--------------------
直接用com
------解决方案--------------------
直接用com... 支持楼上
------解决方案--------------------
没用过 同意楼上的意见 用 com 吧
------解决方案--------------------
为啥要自己写啊
excel9.cpp
fm20.cpp
vbe6ext.cpp
这几个类都可以用EXCEL9.OLB生成出来,添加就好了
------解决方案--------------------
#import "libid:2DF8D04C-5BFA-101B-BDE5-00AA0044DE52" version("2.3") lcid("0") rename("RGB","_RGB"), rename("DocumentProperties","_DocumentProperties")
#import "libid:0002E157-0000-0000-C000-000000000046" version("5.3") lcid("0")
#import "libid:00020813-0000-0000-C000-000000000046" version("1.5") lcid("0") rename("DialogBox", "_DialogBox") rename("RGB", "_RBG") \
rename("DocumentProperties", "_DocumentProperties") rename("CopyFile", "_CopyFile") rename("ReplaceText", "_ReplaceText") exclude("IFont","IPicture")
using namespace Excel;
------解决方案--------------------
可以考虑不要这样用,直接用CBasicExecl or SpreadSheet操作Execl表.
------解决方案--------------------
BasicExecl很好用的.而且速度也很快.
http://www.codeproject.com/KB/database/cspreadsheet.aspx
http://www.codeproject.com/KB/office/BasicExcel.aspx
------解决方案--------------------
http://blog.sina.com.cn/s/blog_4504388f0100073f.html
http://blog.****.net/bodybo/article/details/4219242
好好看看