Linking...
OpExcelFileDlg.obj : error LNK2001: unresolved external symbol "public: struct IDispatch * __thiscall Workbooks::Open(char const *,struct tagVARIANT const &,struct tagVARIANT const &,struct tagVARIANT const &,struct tagVARIANT const &,struct tagVARI
ANT const &,struct tagVARIANT const &,struct tagVARIANT const &,struct tagVARIANT const &,struct tagVARIANT const &,struct tagVARIANT const &,struct tagVARIANT const &,struct tagVARIANT const &,struct tagVARIANT const &,struct tagVARIANT const &)" (
?Open@Workbooks@@QAEPAUIDispatch@@PBDABUtagVARIANT@@1111111111111@Z)
OpExcelFileDlg.obj : error LNK2001: unresolved external symbol "public: void __thiscall _Application::SetVisible(int)" (?SetVisible@_Application@@QAEXH@Z)
Debug/OpExcelFile.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Creating browse info file...
OpExcelFile.exe - 3 error(s), 0 warning(s)
5 个解决方案
#1
Excel的还真没做过,贴个老帖子一起学习下
http://topic.csdn.net/u/20070412/09/8f2c83d1-5979-4e76-aed0-6d2ed436f3b9.html
http://topic.csdn.net/u/20070412/09/8f2c83d1-5979-4e76-aed0-6d2ed436f3b9.html
#2
出现这样的错误提示,一种情况是找不到相应的函数;再就是楼主导入的COM函数使用时出错,比如16个参数的,你只给它传了9个参数。
#3
可能是项目中少.h或.cpp文件了,使用一下Add to project!
#4
调用excel应该用COM吧
import tlb
然后createinstance
import tlb
然后createinstance
#5
打开MFC ClassWizard窗口(查看—>建立类向导),选择Automation,单击Add Class按钮,选择From a type library...,弹出文件选择对话框,之后定位到Microsoft Office的安装目录(通常为C:\Program Files\Microsoft Office\Office),选择EXCEL.exe,选择列表中的所有类,单击OK按钮
打开TestExcel.cpp文件,修改CTestExcelApp::InitInstance(),加入如下代码:
打开stdafx.h头文件确保包含如下头文件:
#include <afxdisp.h>
#include "excel9.h"
BOOL CTestExcelApp::InitInstance()
{
if( !AfxOleInit() ){
AfxMessageBox("初始化Ole出错!");
return FALSE;
}
在OnButton1()函数中,添加代码:
void CTestExcelDlg::OnButton1()
{
// TODO: Add your control notification handler code here
_Application app;
Workbooks books;
_Workbook book;
Worksheets sheets;
_Worksheet sheet;
Range range;
Font font;
Range cols;
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
if( !app.CreateDispatch("Excel.Application") ){
this->MessageBox("无法创建Excel应用!");
return;
}
books=app.GetWorkbooks();
book=books.Add(covOptional);
sheets=book.GetSheets();
sheet=sheets.GetItem(COleVariant((short)1));
range=sheet.GetRange(COleVariant("A1"),COleVariant("A1"));
range.SetValue(COleVariant("HELLO EXCEL!"));
font=range.GetFont();
font.SetBold(COleVariant((short)TRUE));
range=sheet.GetRange(COleVariant("A2"),COleVariant("A2"));
range.SetFormula(COleVariant("=RAND()*100000"));
range.SetNumberFormat(COleVariant("$0.00"));
cols=range.GetEntireColumn();
cols.AutoFit();
app.SetVisible(TRUE);
app.SetUserControl(TRUE);
打开TestExcel.cpp文件,修改CTestExcelApp::InitInstance(),加入如下代码:
打开stdafx.h头文件确保包含如下头文件:
#include <afxdisp.h>
#include "excel9.h"
BOOL CTestExcelApp::InitInstance()
{
if( !AfxOleInit() ){
AfxMessageBox("初始化Ole出错!");
return FALSE;
}
在OnButton1()函数中,添加代码:
void CTestExcelDlg::OnButton1()
{
// TODO: Add your control notification handler code here
_Application app;
Workbooks books;
_Workbook book;
Worksheets sheets;
_Worksheet sheet;
Range range;
Font font;
Range cols;
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
if( !app.CreateDispatch("Excel.Application") ){
this->MessageBox("无法创建Excel应用!");
return;
}
books=app.GetWorkbooks();
book=books.Add(covOptional);
sheets=book.GetSheets();
sheet=sheets.GetItem(COleVariant((short)1));
range=sheet.GetRange(COleVariant("A1"),COleVariant("A1"));
range.SetValue(COleVariant("HELLO EXCEL!"));
font=range.GetFont();
font.SetBold(COleVariant((short)TRUE));
range=sheet.GetRange(COleVariant("A2"),COleVariant("A2"));
range.SetFormula(COleVariant("=RAND()*100000"));
range.SetNumberFormat(COleVariant("$0.00"));
cols=range.GetEntireColumn();
cols.AutoFit();
app.SetVisible(TRUE);
app.SetUserControl(TRUE);
#1
Excel的还真没做过,贴个老帖子一起学习下
http://topic.csdn.net/u/20070412/09/8f2c83d1-5979-4e76-aed0-6d2ed436f3b9.html
http://topic.csdn.net/u/20070412/09/8f2c83d1-5979-4e76-aed0-6d2ed436f3b9.html
#2
出现这样的错误提示,一种情况是找不到相应的函数;再就是楼主导入的COM函数使用时出错,比如16个参数的,你只给它传了9个参数。
#3
可能是项目中少.h或.cpp文件了,使用一下Add to project!
#4
调用excel应该用COM吧
import tlb
然后createinstance
import tlb
然后createinstance
#5
打开MFC ClassWizard窗口(查看—>建立类向导),选择Automation,单击Add Class按钮,选择From a type library...,弹出文件选择对话框,之后定位到Microsoft Office的安装目录(通常为C:\Program Files\Microsoft Office\Office),选择EXCEL.exe,选择列表中的所有类,单击OK按钮
打开TestExcel.cpp文件,修改CTestExcelApp::InitInstance(),加入如下代码:
打开stdafx.h头文件确保包含如下头文件:
#include <afxdisp.h>
#include "excel9.h"
BOOL CTestExcelApp::InitInstance()
{
if( !AfxOleInit() ){
AfxMessageBox("初始化Ole出错!");
return FALSE;
}
在OnButton1()函数中,添加代码:
void CTestExcelDlg::OnButton1()
{
// TODO: Add your control notification handler code here
_Application app;
Workbooks books;
_Workbook book;
Worksheets sheets;
_Worksheet sheet;
Range range;
Font font;
Range cols;
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
if( !app.CreateDispatch("Excel.Application") ){
this->MessageBox("无法创建Excel应用!");
return;
}
books=app.GetWorkbooks();
book=books.Add(covOptional);
sheets=book.GetSheets();
sheet=sheets.GetItem(COleVariant((short)1));
range=sheet.GetRange(COleVariant("A1"),COleVariant("A1"));
range.SetValue(COleVariant("HELLO EXCEL!"));
font=range.GetFont();
font.SetBold(COleVariant((short)TRUE));
range=sheet.GetRange(COleVariant("A2"),COleVariant("A2"));
range.SetFormula(COleVariant("=RAND()*100000"));
range.SetNumberFormat(COleVariant("$0.00"));
cols=range.GetEntireColumn();
cols.AutoFit();
app.SetVisible(TRUE);
app.SetUserControl(TRUE);
打开TestExcel.cpp文件,修改CTestExcelApp::InitInstance(),加入如下代码:
打开stdafx.h头文件确保包含如下头文件:
#include <afxdisp.h>
#include "excel9.h"
BOOL CTestExcelApp::InitInstance()
{
if( !AfxOleInit() ){
AfxMessageBox("初始化Ole出错!");
return FALSE;
}
在OnButton1()函数中,添加代码:
void CTestExcelDlg::OnButton1()
{
// TODO: Add your control notification handler code here
_Application app;
Workbooks books;
_Workbook book;
Worksheets sheets;
_Worksheet sheet;
Range range;
Font font;
Range cols;
COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
if( !app.CreateDispatch("Excel.Application") ){
this->MessageBox("无法创建Excel应用!");
return;
}
books=app.GetWorkbooks();
book=books.Add(covOptional);
sheets=book.GetSheets();
sheet=sheets.GetItem(COleVariant((short)1));
range=sheet.GetRange(COleVariant("A1"),COleVariant("A1"));
range.SetValue(COleVariant("HELLO EXCEL!"));
font=range.GetFont();
font.SetBold(COleVariant((short)TRUE));
range=sheet.GetRange(COleVariant("A2"),COleVariant("A2"));
range.SetFormula(COleVariant("=RAND()*100000"));
range.SetNumberFormat(COleVariant("$0.00"));
cols=range.GetEntireColumn();
cols.AutoFit();
app.SetVisible(TRUE);
app.SetUserControl(TRUE);