C# 中单词的后期绑定
我正在开发一个应用程序,需要与2003、2007、2010版本的MSWord和PPT进行交互。我读了一些文章,发现后期绑定是最好的选择。
有人可以发布一些示例代码如何对Word和PPT进行操作吗?
比如如何获取应用程序正在运行的实例,无论其版本如何?
I am developing an application which need to interact with 2003, 2007, 2010 versions of MSWord and PPT. I read some articles and found that Late binding is the best option.
Could somebody post some sample code how to do it for word and PPT?
Like how to get the running instances of application irrespective of their version?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好的选择是使用 Ms Word / PowerPoint 对象库,这使得 .net 的 com intero 变得非常简单。这里有一个很好的分步说明:
http://www .c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx
以及必需的 Microsoft 教程:
http://support.microsoft.com/kb/316384
这里有一篇关于 COM 后期绑定的好文章:
http://www.devarticles.com/c/a/C-Sharp/Using-Late-Bound-COM-Objects/< /a>
尽管您可能需要注意 Microsoft 发出的关于在早期绑定可用时使用 COM 后期绑定对性能影响的警告!
或者,您可能想看看 aspose Libraries 用于 Office 文件操作,如果您想要一个漂亮的 api 并且更喜欢避免使用 COM。虽然价格昂贵,但我已经广泛使用它们,并发现从开发的角度来看它们要优越得多。
Your best bet is to use the Ms Word / PowerPoint object libraries which make the com intero really quite simple from .net. There is a nice step by step here for the word:
http://www.c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx
Along with the obligatory Microsoft tutorial:
http://support.microsoft.com/kb/316384
There is a good article on late binding with COM here:
http://www.devarticles.com/c/a/C-Sharp/Using-Late-Bound-COM-Objects/
Though you may want to heed the warning Microsoft give about the performance implications of using late binding of COM when early binding is available!
Alternatively you may want to take a look at the aspose Libraries for office file manipulation if you want a nice api and prefer to avoid COM. There pricy but I have used them extensively and find them far superior from a dev point of view.
NetOffice (http://netoffice.codeplex.com) 是一组免费的、与版本无关的 Office 互操作程序集。它支持所有 Office 版本,甚至告诉您哪些 Office 版本支持特定方法:
NetOffice (http://netoffice.codeplex.com) is a free set of version-independent interop assemblies for Office. It supports all Office versions and even tells you which Office versions support a particular method: