Microsoft Word自动化 - 在VC ++中嵌入Word MFC SDI - 保存文档时出错 [英] Microsoft Word Automation - Embedding Word in VC++ MFC SDI - Error saving the document

查看:81
本文介绍了Microsoft Word自动化 - 在VC ++中嵌入Word MFC SDI - 保存文档时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,




我试图在Microsoft MFC SDI SDK应用程序中嵌入microsoft字。我可以使用以下MSDN帮助程序执行此操作:


如何使用MFC嵌入和自动化Word文档



但是当试图保存时该文件,它正在抛出一条错误信息。以下是保存文档的代码。 

   LPDISPATCH lpDisp  ;   
lpDisp
= m_pItem - > GetIDispatch ();

_文件 doc ;

doc
AttachDispatch lpDisp );

doc
保存 ();



这里我试图使用以下函数保存已打开的文档:

   CString   strPath   =    " D:\\Test.doc"  ;   
m_pItem
- > CreateFromFile strPath m_clsid );



以下是调用函数doc.Save()时的错误消息:



保存方法或属性不可用,因为此文档正在另一个程序中编辑


请帮助我解决此问题。


谢谢和问候,


Alvin


解决方案

嗨Alvin,


谢谢在此处发布。


>> Microsoft Word自动化 - 在VC ++中嵌入Word MFC SDI - 错误保存文档


在调用save方法之前,您似乎需要关闭文档对象。


或者你可以使用
SaveAs
方法使用新名称或格式保存指定的文档。


如果查看文档,您将看到示例代码不创建文件,而是使用GetDocument和CEmbedWordCntrItem来创建一个与此文档相关联的新项目。


希望这可以为您提供帮助。


最好的问候,


Baron Bi




Dear friends,

I am trying to embed microsoft word inside an MFC SDI SDK application. And I could able to do this using the following MSDN help program:

How to embed and automate a Word document with MFC

But when trying to save the document, it is throwing an error message. Below is the code for saving the document. 

LPDISPATCH lpDisp;
lpDisp = m_pItem->GetIDispatch();

_Document doc;

doc.AttachDispatch(lpDisp);

doc.Save();

Here I am trying to save the document which is already opened using the below function:

CString strPath = "D:\\Test.doc";
m_pItem->CreateFromFile(strPath, m_clsid);

Following is the error message when calling the function doc.Save():

The save method or property is not available because this document is being edited in another program

Please some one help me to fix this issue.

Thanks and Regards,

Alvin

解决方案

Hi Alvin,

thanks for posting here.

>>Microsoft Word Automation - Embedding Word in VC++ MFC SDI - Error saving the document

It seems you need to close the document object before you call save method.

Or you could use SaveAs method to save the specified document with a new name or format.

If you look into the document, you'll see the sample code doesn't create a file, instead it uses GetDocument and CEmbedWordCntrItem to create a new item associated with this document.

Hope this could be help of you.

Best Regards,

Baron Bi


这篇关于Microsoft Word自动化 - 在VC ++中嵌入Word MFC SDI - 保存文档时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆