I added the reference Microsoft.Excel.16.0.Object.Library to be able to process in Excel. However, the program I wrote is giving errors to other computers. Because their computers have older versions of this library. Can I make my program workable in all versions of these libraries?
-
Since MS Office documents are nothing more than zipped collections of XML files you don't need to use interop. You might consider a library like ClosedXML. – Crowcoder Nov 26 '17 at 21:14
-
use `OpenXML or ClosedXML` bypass Interop no need for it these days.. – MethodMan Nov 26 '17 at 21:21
-
Was the answer helpful to you? – wp78de Jul 16 '18 at 03:47
1 Answers
If you really need to rely on interop you should use late binding. That way you can reference the installed version of the library at runtime.
In contrast to early binding, late binding waits until runtime to bind property and method calls to their objects. To do this, the target object must implement a special COM interface: IDispatch. The IDispatch::GetIDsOfNames method allows Visual C# to interrogate an object about what methods and properties it supports and the IDispatch::Invoke method then allows Visual C# to call those methods and properties. Late binding in this fashion has the advantage of removing some of the version dependencies that are inherent with early binding. However, it has the disadvantages of removing compile-time checks on the integrity of automation code, as well as not providing Intellisense features that can provide clues to correct calls to methods and properties. See: KB 302902: Binding for Office Automation Servers with Visual C# .NET. for more information about using late binding in C#, and here.
However, late binding in C# can be a pain. Anyways, in order to use late binding follow the steps described here.

- 18,207
- 7
- 43
- 71