部分源代码如下:
CString strPath = "D:\\test.xlt";
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;
//创建Excel 2000服务器(启动Excel)
if (!ExcelApp.CreateDispatch("Excel.Application",NULL))
{
AfxMessageBox("Create Excel service failure!");
return;
}
ExcelApp.SetVisible(false);头文件包含有:
#include "comdef.h"
#include "Excel9.h"
我用的是excel2000,总是提示“Create Excel service failure!"
CString strPath = "D:\\test.xlt";
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;
//创建Excel 2000服务器(启动Excel)
if (!ExcelApp.CreateDispatch("Excel.Application",NULL))
{
AfxMessageBox("Create Excel service failure!");
return;
}
ExcelApp.SetVisible(false);头文件包含有:
#include "comdef.h"
#include "Excel9.h"
我用的是excel2000,总是提示“Create Excel service failure!"
这个对象看你的代码好像都没有附值~~~
ExcelApp = new _Application;//试试看
if (!ExcelApp)
{
AfxMessageBox("new _Application; Failed!", MB_OK);
return FALSE;
}
假如还不行的话,确保在CYourApp::InitInstance/ExitInstance 里面分别调用了 CoInitialize/CoUninitialize;
对了,用AfxOleInit()进行初始化了没有??~
BOOL CShiyan3Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
........
if (CoInitialize(NULL)!=0)
{
AfxMessageBox("初始化COM支持库失败!");
exit(1);
}
CoUninitialize();//昏头的代码
return TRUE; // return TRUE unless you set the focus to a control
}一切解决,散分!