将自定义文件格式添加到 Word 2007“另存为”对话框
我想在 Word 2007 中添加导出到新文件格式的选项。理想情况下,如果该选项可以是 Word 2007“另存为”对话框中用户可以在文件格式下拉框中选择的另一种文件格式,那就太好了。
虽然我有很多 .NET 经验,但我还没有为 MS Office 做过太多开发。从高层次来看,使用 .NET 将另一种另存为格式添加到 Word 2007 中时,我应该注意什么?
I want to add the option to export to a new file format in Word 2007. Ideally it would be nice if the option could be another file format in the Word 2007 Save As dialog that the user could select in the file format dropdown box.
Although I have a lot of .NET experience I haven't done much development for MS Office. At a high level what should I look at to add another save as format to Word 2007 using .NET?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Word 2007 中,您基本上有两个选项来添加自己的自定义文件导出过滤器:
从 Office 2007 SP2 开始,您可以包含基于 OpenXML 的导出过滤器,请参阅 介绍适用于 2007 Microsoft Office System SP2 的 Open XML 格式外部文件转换器了解详细信息。
对于所有 Word 版本(回到 Word 97 或更早版本),您可以使用作为 Win32 dll 实现的基于 RTF 的导出过滤器: 如何获取 WinWord Converter SDK (GC1039)
You basically have two options in Word 2007 to add your own custom file export filters:
From Office 2007 SP2 on you can include an OpenXML based export filter, see Introducing the Open XML Format External File Converter for 2007 Microsoft Office System SP2 for the details.
For all Word versions (back to Word 97 or maybe even earlier) you can use an RTF-based export filter implemented as a Win32 dll: How to Obtain the WinWord Converter SDK (GC1039)
看一下
Microsoft.Office.Core.FileDialog
接口及其Filters
属性(类型为Microsoft.Office.Core.FileDialogFilters
) ,您可以在其中添加和删除过滤器。它们包含在 Office.dll 中的 Visual Studio Tools for Office 12 中。要获取正确的
FileDialog
对象,首先获取 Microsoft.Office.Interop.Word.Application 实例(通常通过创建新的ApplicationClass
或等效地使用 VBA 的>CreateObject
)并将其命名为application
。然后执行如下操作:实际代码可以位于 COM 加载项中,也可以位于使用 COM 打开 Word/与 Word 交互的外部程序中。至于替换内置“另存为”对话框,您还需要在某处处理
Microsoft.Office.Interop.Word.Application.DocumentBeforeSave
事件(VBA,使用此代码等)来拦截默认行为。这是一个“另存为”处理程序的示例:
Take a look at the
Microsoft.Office.Core.FileDialog
interface and itsFilters
property (which is typeMicrosoft.Office.Core.FileDialogFilters
), where you can add and remove filters. They are included with Visual Studio Tools for Office 12, in Office.dll.As to getting the correct
FileDialog
object, first acquire a Microsoft.Office.Interop.Word.Application instance (usually by creating a newApplicationClass
or, equivalently, using VBA'sCreateObject
) and call itapplication
. Then do something like the following:The actual code can either be in a COM Add-In, or an external program that uses COM to open/interact with Word. As to replacing the built-in Save As dialog, you'll also need to handle the
Microsoft.Office.Interop.Word.Application.DocumentBeforeSave
event somewhere (VBA, with this code, etc) to intercept the default behavior.Here's an example 'save as' handler:
无法保存为自定义格式或通过对象模型更改“另存为”对话框。目前,这看起来像是 http://msdn.microsoft 的唯一方法。 com/en-us/library/aa338206.aspx
It's not possible to save to a custom format or change the SaveAs dialog through the Object Model. Right now, this is looking like the only way http://msdn.microsoft.com/en-us/library/aa338206.aspx