Search code examples
c#excelcom-interop

Excel automation in c# for 2003-2010 version via com interoperability


There are different office version, different com type libraries for managing them.

Could anyone tell me how should i write the code to operate on different Excel version? What about PIA for office, should I include them all with the project?

How to solve the problem of office multiversioning?


Solution

  • 1) take advantage of the dynamic binding

    2) stick with late binding

    and your code will work on any version.

    // work with any version
    Type wordType = Type.GetTypeFromProgId( "Word.Application" );
    
    dynamic wordApp = Activator.CreateInstance( wordType );
    
    // late binding + dynamics - always works
    wordApp.Visible = true;