VC中使用import方式引入word:
#import "D:\工具\office2000\Office\msword9.olb" rename("ExitWindows", "WordExitWindows")
生成msword9.tli和msword9.tlh
在程序中调用:
Word::_DocumentPtr pDoc(disp); //获取word对象
if(pDoc!=NULL){
Word::WindowPtr activeWin = pDoc->GetActiveWindow();
Word::PanePtr pane = activeWin->GetActivePane();
Word::ViewPtr view = pane->GetView();
Word::WdViewType vtype;
vtype = view->GetType();
.....
}
编译后报错:
d:\...\debug\msword9.tli(27944) : error C2556: 'enum WdViewType __thiscall Word::View::GetType(void)' : overloaded function differs only by return type from 'enum Word::WdViewType __thiscall Word::View::GetType(void)'
d:\...\debug\msword9.tlh(25148) : see declaration of 'GetType'
d:\...\debug\msword9.tli(27944) : error C2371: 'GetType' : redefinition; different basic types
d:\...\debug\msword9.tlh(25148) : see declaration of 'GetType'
Error executing cl.exe.dsoflks.obj - 2 error(s), 0 warning(s)关于getview函数msword9.tli中的声明是这样的:
#pragma implementation_key(3684)
inline enum WdViewType Word::View::GetType ( ) {
enum WdViewType _result;
HRESULT _hr = get_Type(&_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _result;
}请问各位老大这个错误是什么意思,怎么解决?
#import "D:\工具\office2000\Office\msword9.olb" rename("ExitWindows", "WordExitWindows")
生成msword9.tli和msword9.tlh
在程序中调用:
Word::_DocumentPtr pDoc(disp); //获取word对象
if(pDoc!=NULL){
Word::WindowPtr activeWin = pDoc->GetActiveWindow();
Word::PanePtr pane = activeWin->GetActivePane();
Word::ViewPtr view = pane->GetView();
Word::WdViewType vtype;
vtype = view->GetType();
.....
}
编译后报错:
d:\...\debug\msword9.tli(27944) : error C2556: 'enum WdViewType __thiscall Word::View::GetType(void)' : overloaded function differs only by return type from 'enum Word::WdViewType __thiscall Word::View::GetType(void)'
d:\...\debug\msword9.tlh(25148) : see declaration of 'GetType'
d:\...\debug\msword9.tli(27944) : error C2371: 'GetType' : redefinition; different basic types
d:\...\debug\msword9.tlh(25148) : see declaration of 'GetType'
Error executing cl.exe.dsoflks.obj - 2 error(s), 0 warning(s)关于getview函数msword9.tli中的声明是这样的:
#pragma implementation_key(3684)
inline enum WdViewType Word::View::GetType ( ) {
enum WdViewType _result;
HRESULT _hr = get_Type(&_result);
if (FAILED(_hr)) _com_issue_errorex(_hr, this, __uuidof(this));
return _result;
}请问各位老大这个错误是什么意思,怎么解决?
解决方案 »
- 已经定义了的宏或者已声明的函数,点击“转到定义(声明)”后出现“未定义的符号XXX”
- 调指定应用程序打开指定目录的文件?
- vc++程序逻辑错误:
- [关于MFC中 tree control 获取选中项序号的问题,大家帮我看看 谢谢了,谢谢谢谢,谢谢谢谢,谢谢谢谢,谢谢谢谢,谢谢谢谢,谢谢谢谢,谢谢谢谢]
- 菜鸟的问题,这个要怎么写啊~~呜呜
- 如何编写一个高性能的文件服务器?(50分)
- GetWindowText()的作用是什么?
- 我有并口读数据代码,你们能提供发数据吗?加分
- 一个不大不小的问题????????
- 如何改变StatusBar的高度?请高手指教,很着急。
- 用MFC建立ACTIVE X工程 Test,如何获取类CTestCtrl实例的指针?,
- 替MM求<Visual C++网络高级编程>电子书
#import "G:\Program Files\Microsoft Office\Office11\MSWORD.OLB" named_guids raw_interfaces_only rename("ExitWindows", "wordExitWindows")
void html_to_word()
{
printf("Automate word to save xxx.htm as onega.doc, test by masterz with VC.NET2003 on Windowx2003, Office2003\n");
Word::_ApplicationPtr app;
app.CreateInstance("Word.Application");
app->put_DisplayAlerts(Word::wdAlertsNone);
Word::DocumentsPtr docs;
app->get_Documents(&docs);
Word::_DocumentPtr doc;
_variant_t vFileName("c:\\a.htm");
_variant_t vOptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
_variant_t vTrue(VARIANT_TRUE);
_variant_t vFalse(VARIANT_FALSE);
docs->Open (
/*[in]*/&vFileName,
/*[in] VARIANT * ConfirmConversions*/&vOptional,
/*[in] VARIANT * ReadOnly*/&vOptional,
/*[in] VARIANT * AddToRecentFiles*/&vOptional,
/*[in] VARIANT * PasswordDocument*/&vOptional,
/*[in] VARIANT * PasswordTemplate*/&vOptional,
/*[in] VARIANT * Revert*/&vOptional,
/*[in] VARIANT * WritePasswordDocument*/&vOptional,
/*[in] VARIANT * WritePasswordTemplate*/&vOptional,
/*[in] VARIANT * Format*/&vOptional,
/*[in] VARIANT * Encoding*/&vOptional,
/*[in] VARIANT * Visible*/&vOptional,
/*[in] VARIANT * OpenAndRepair*/&vOptional,
/*[in] VARIANT * DocumentDirection*/&vOptional,
/*[in] VARIANT * NoEncodingDialog*/&vOptional,
/*[in] VARIANT * XMLTransform*/&vOptional ,
/*[out,retval]*/ &doc );
_variant_t vCopies((short)1);
LPCTSTR save_file_name = _T("c:\\onega.doc");
DeleteFile(save_file_name);
_variant_t filename(save_file_name);
_variant_t FileFormat((long)Word::wdFormatDocument);
doc->SaveAs (&filename,&FileFormat);
doc->put_Saved(VARIANT_TRUE);
app->Quit(&vOptional,&vOptional,&vOptional);}
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
html_to_word();
CoUninitialize();
printf("program end!\n");
return 0;
}
http://www.vckbase.com/document/viewdoc/?id=1408