在ExcelFile.cpp源文件中添加判断语句
原来的:
BOOL CExcelFile::InitExcel()
{
//创建Excel 2000服务器(启动Excel)
if (!excel_application_.CreateDispatch(_T("Excel.Application"),NULL))
{
AfxMessageBox(_T("创建Excel服务失败,你可能没有安装EXCEL,请检查!"));
return FALSE;
}
excel_application_.put_DisplayAlerts(FALSE);
return TRUE;
}
添加过后:
BOOL CExcelFile::InitExcel()
{
if (S_OK != CoInitialize(NULL)) {
//cerr << "Initialize com failed..." << endl;
return -1;
}
//创建Excel 2000服务器(启动Excel)
if (!excel_application_.CreateDispatch(_T("Excel.Application"),NULL))
{
AfxMessageBox(_T("创建Excel服务失败,你可能没有安装EXCEL,请检查!"));
return FALSE;
}
excel_application_.put_DisplayAlerts(FALSE);
return TRUE;
}