乔山办公网我们一直在努力
您的位置:乔山办公网 > word文档 > <em>mfc</em>程序怎么实现打开<em>word</em>文档-

<em>mfc</em>程序怎么实现打开<em>word</em>文档-

作者:乔山办公网日期:

返回目录:word文档


1 在MFC中建一个菜单项, 用classwazid添加消息处理到菜单项即可。
2 在消息处理函数中,添加对word的处理,一般使用自动化接口,参阅http:///joeblackzqq/archive/2010/11/07/1871374.html

调用word打开,可以搜一搜"MFC如何运行word"的资料
ShellExecute(NULL,"open",file,NULL,NULL,SW_SHOWNORMAL);
file是你的文件路径

#include "stdafx.h"

#pragma warning(disable:4259)
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\Office11\\MSO.DLL" rename("IAccessible", "msoIAccessible")
using namespace Office;
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.OLB"
//using namespace VBIDE;
#import "d:\\Program Files\\Microsoft Office\\OFFICE11\\MSWORD.OLB" rename("ExitWindows","WordExitWindows")
using namespace Word;
#include <atlbase.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(0);
{
e799bee5baa6e4b893e5b19e338_ApplicationPtr m_WordPtr;
DocumentsPtr m_DocsPtr;
_DocumentPtr m_DocPtr;
HRESULT hr;
try{
//CLSID sid;
//CLSIDFromProgID(L"word.application",&sid);
hr=m_WordPtr.CreateInstance(__uuidof(Application));

m_WordPtr->put_Visible(VARIANT_TRUE);
m_DocPtr=m_WordPtr->Documents->Add();

LPSTR a = "c:\\22.doc";
CComBSTR b = a;
BSTR c = b.m_str;
VARIANT va;
va.vt = VT_BSTR;
va.bstrVal = c;
m_WordPtr->Documents->Open(&va);
SelectionPtr sel=m_WordPtr->GetSelection();
sel->TypeText(_bstr_t("sadsaS12as"));
sel->MoveEnd();
InlineShapePtr sh=sel->GetInlineShapes()->AddPicture(_bstr_t("c:\\1.jpg"));
sel->SetRange(1,2);
//sel->TypeText(_bstr_t("!!!!!!!"));
_bstr_t text=sel->GetText();
char *s=_com_util::ConvertBSTRToString(text);
cout<<s<<endl;

TablesPtr tables = sel->GetTables();
TablePtr table = tables->Add(sel->GetRange(), 2, 5);
BordersPtr bords = table->GetBorders();
bords->PutOutsideLineStyle(wdLineStyleSingle);
bords->PutOutsideLineWidth(wdLineWidth150pt);
bords->PutInsideLineStyle(wdLineStyleSingle);
for (int i = 1; i<=2; i++)
{
for (int j = 1; j<=5; j++)
{
table->Cell(i,j)->GetRange()->PutText("20");
}
}
CellPtr cell = table->Cell(1,1);
cell->Merge(table->Cell(1,2));

sel->Delete();
m_WordPtr->GetActiveDocument()->SaveAs(&CComVariant("c:\\1.doc"));
//m_WordPtr->Quit();
}
catch(_com_error *e)
{
MessageBox(NULL, "haha ", "no word ",MB_OK);
return -1;
}
}
CoUninitialize();
return 0;

}

把导入库改为你的word配置的正确路径即可

相关阅读

  • <em>mfc</em>程序怎么实现打开<em>word</em>文档-

  • 乔山办公网word文档
  • 1 在MFC中建一个菜单项, 用classwazid添加消息制处理到菜单项即可。2 在消息处理函数中,添加对word的处知理,一般使用自动道化接口,参阅http:///joeblackzqq/archive/2010/11/07/1871374.htmlword,怎
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网