MFC读EXCEL

再谈MFC操作Excel2007(VS2005+excel2007)
网上已经很多VC6+Excel(version X)的例子了,无非就是
1.在CLASS FROM TYPELIB找excel9.olb或者excel.exe.
2.把_Application这些选中,生成excel.h和excel.cpp.
小弟用的是VS2005,这第二步呢,Application,WorkSheet这些每个类就会生成一个文件,如果选中网上提到的

C/C++ code
_Application ExcelApp; 
Workbooks workbooks;
_Workbook workbook; 
Worksheets sheets; 
_Worksheet sheet; 
Range range;

这些类的话,就会生成6个.h文件。
当然这还不是关键,老火的是,生成这些头文件后,没有生成对应的*.cpp文件。
好了,我忍了!据说有时没有cpp也能成功的。于是我进行第三步。
3.把excel.h文件include到testDlg.cpp中。
杯具开始了,400多个错误之后,编译停止。查看了一下这些错误:
d:\work2\sys\src\test\t3\t3\debug\excel.tlh(1463) : error C2371: 'FontPtr' : redefinition; different basic types
1> d:\program files (x86)\microsoft visual studio 8\vc\include\comdef.h(322) : see declaration of 'FontPtr'
1>d:\work2\sys\src\test\t3\t3\debug\excel.tlh(1541) : error C2786: 'BOOL (__stdcall *)(HDC,int,int,int,int)' : invalid operand for __uuidof
1>d:\work2\sys\src\test\t3\t3\debug\excel.tlh(1541) : error C2923: '_com_IIID' : 'Rectangle' is not a valid template type argument for parameter '_Interface'
1> d:\program files (x86)\microsoft visual studio 8\vc\platformsdk\include\wingdi.h(3514) : see declaration of 'Rectangle'
貌似都和这个debug目录下的excel.tlh文件有关。

不知道有没有同学也用过,我是VS2005+Excel2007,热血求解决方法。

------解决方案--------------------
我记得当时我是Import部分DLL,然后用Rename来解决重定义问题的。

回去找下当时的代码 
------解决方案--------------------
#import "C:\Program Files\Common Files\Microsoft Shared\OFFICE11\mso.dll" rename("RGB", "MSRGB")
#import "C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6EXT.OLB" raw_interfaces_only, rename("Reference", "ignorethis"), rename("VBE", "testVBE")
#import "D:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE" exclude("IFont","IPicture"), rename("RGB", "ignorethis"), rename("DialogBox", "ignorethis"), rename("VBE", "testVBE"), rename("ReplaceText", "EReplaceText"), rename("CopyFile","ECopyFile"), rename("FindText", "EFindText"), rename("NoPrompt", "ENoPrompt")

自己把路径改了,对应好自己的路径看看 

实现

excel

的读写操作

 

这个是使用

ODBC

来完成的

 

第一步:建立基于对话框的

MFC

工程,命名为

MfctoExc

 

第二步:添加两个头文件到

stdafx.h

 

         

#include 

<afxdb.h> 

           

#include 

<odbcinst.h> 

第三步:添加两个按钮控件和一个

List 

Box

控件,给

List 

Box

添加控制变量

CListBox 

m_ExcelList;

添加

DDX_Control(pDX, 

IDC_LIST_BOX, 

m_ExcelList);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值