3,245
社区成员
发帖
与我相关
我的任务
分享
if (::CoInitialize(NULL) != 0)
{
AfxMessageBox("初始化COM失败");
return;
}
_Application app;
app.CreateDispatch(_T("Word.Application"));
app.SetVisible(TRUE);
Documents docs = app.GetDocuments();
CComVariant Template(_T("")); //不使用模板
CComVariant NewTemplate(false), DocumentType(0),Visible;
docs.Add(&Template,&NewTemplate,&DocumentType,&Visible);
Selection sel=app.GetSelection();
//调用函数Selection::TypeText 向WORD发送字符
sel.TypeText(_T("HELLO\r\n大家好呀"));
Range selRange = sel.GetRange();
InlineShapes inlineShapes = sel.GetInlineShapes();
CComVariant linktoFile(false),SaveWithDocument(false),range;
inlineShapes.AddPicture(_T("F:\\13.jpg"),&linktoFile,&SaveWithDocument,&range);