问一个C++在windows 下读取excel的问题?
我刚才在论坛里搜索了一下,很多帖子,我贴了一段代码
CString strFilePath = L"111.xls";
COleVariant
covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
_Application ExcelApp;
Workbooks wbsMyBooks;
_Workbook wbMyBook;
Worksheets wssMysheets;
_Worksheet wsMysheet;
Range rgMyRge;
if(!ExcelApp.CreateDispatch("Excel.Application",NULL))
{
AfxMessageBox("创建Excel服务失败!");
exit(1);
}
wbsMyBooks.AttachDispatch(ExcelApp.GetWorkbooks(),true);
wbMyBook.AttachDispatch(wbsMyBooks.Add(_variant_t(strFilePath)));
wssMysheets.AttachDispatch(wbMyBook.GetWorksheets(),true);
wsMysheet.AttachDispatch(wssMysheets.GetItem(_variant_t("sheet3")),true);
rgMyRge.AttachDispatch(wsMysheet.GetCells(),true);
int column = rgMyRge.GetColumn();
int row = rgMyRge.GetRow();
VARIANT tt;
///////////////
Range cell;//增加一个对象
cell.AttachDispatch(rgMyRge.GetItem(COleVariant((long)1),COleVariant((long)1)).pdispVal,true);
tt = cell.GetValue2();//取值
////////////
CString yy;
yy = tt.bstrVal;
// AfxMessageBox(yy);//输出值
cell.ReleaseDispatch();
rgMyRge.ReleaseDispatch();
wsMysheet.ReleaseDispatch();
wssMysheets.ReleaseDispatch();
wbMyBook.ReleaseDispatch();
wbsMyBooks.ReleaseDispatch();
ExcelApp.ReleaseDispatch();
这个是通过com接口访问excel把,需要包含什么头文件和库呢,编译一堆错误,谢谢