保存Word文档 [英] Saving Word document

查看:103
本文介绍了保存Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据Word的安装版本保存Word文档;

如果是Word 2003(适当的版本号为11),扩展名为DOC.
如果Word版本高于2003,扩展名为DOCX.

差异体现在发送给SaveAS方法的第二个参数中:

object fileFormat = GraphDocsSettings.Default.WordInstalledVersion > 11.0?     
                WdSaveFormat.wdFormatXMLDocument : WdSaveFormat.wdFormatDocument;

wordDoc.SaveAs(ref outputFile, fileFormat, ref missing, ref missing, ref missing,
                           ref missing, ref missing, ref missing, ref missing,
                           ref missing, ref missing, ref missing, ref missing,
                           ref missing, ref missing, ref missing);  

但是,在使用Interop.Word 11.0时,出现以下错误:

Microsoft.Office.Interop.Word.WDSaveFormat does not contain a definition for wdFormatXMLDocument.  

有什么想法吗?

解决方案

不确定不同单词版本之间的API是否完全相同.

如果我可以提出建议,请使用NetOffice(请参阅链接),而不要使用Office互操作程序集. /p>

该API与Office Interop API相同,并且可与所有(当前)版本的Microsoft Office一起使用.

NB-这是一个示例: http://netoffice.codeplex.com/wikipage?title = Word_Example01

您应导入以下名称空间以使其正常工作:

using NetOffice;
using Word = NetOffice.WordApi;
using NetOffice.WordApi.Enums;
using Office = NetOffice.OfficeApi;

I would like to save a Word document according to the Word installed version;

In case it is Word 2003 (appropriate version number is 11), with DOC extension.
In case the Word version is higer than 2003, with DOCX extension.

The difference is reflected in the second argument sent to the SaveAS method:

object fileFormat = GraphDocsSettings.Default.WordInstalledVersion > 11.0?     
                WdSaveFormat.wdFormatXMLDocument : WdSaveFormat.wdFormatDocument;

wordDoc.SaveAs(ref outputFile, fileFormat, ref missing, ref missing, ref missing,
                           ref missing, ref missing, ref missing, ref missing,
                           ref missing, ref missing, ref missing, ref missing,
                           ref missing, ref missing, ref missing);  

However, When using Interop.Word 11.0 I get the following error:

Microsoft.Office.Interop.Word.WDSaveFormat does not contain a definition for wdFormatXMLDocument.  

Any ideas?

解决方案

Not sure the API is exactly the same between different word versions.

If I can make a suggestion - use NetOffice( see link) instead of the office interop assemblies.

the API is the same as the Office Interop API, and it will work with all (current) versions of Microsoft Office.

NB - Here is a sample: http://netoffice.codeplex.com/wikipage?title=Word_Example01

You should import the following namespaces to get it to work:

using NetOffice;
using Word = NetOffice.WordApi;
using NetOffice.WordApi.Enums;
using Office = NetOffice.OfficeApi;

这篇关于保存Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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