Late binding of word in C#
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 ins开发者_运维问答tances of application irrespective of their version?
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) 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:
精彩评论