support different Office versions with Office Automation

后端 未结 3 1664
孤城傲影
孤城傲影 2020-12-30 05:53

We created an application that uses Office 2007 (Excel 2007) to read in data from an Excel worksheet. However. I noticed that when I want to deploy the application on a syst

相关标签:
3条回答
  • 2020-12-30 06:41

    Depending on whether you have any other requirements (you say reading data from excel), you can use the OLEDB driver to connect to the excel file and query it in a SQL manner.

    Example: http://codehill.com/2009/01/reading-excel-2003-and-2007-files-using-oledb/

    0 讨论(0)
  • 2020-12-30 06:43

    You can reference the PIA's for multiple versions of office, and figure out at runtime which to route your calls from.

    0 讨论(0)
  • 2020-12-30 06:51

    As you're using .NET 4, you can use "embedded" PIAs (aka "No PIA"). Change the option on the Office reference so that "Embed Interop Types" is True.

    So long as you only use features of Office which are supported on the machine you deploy on, you should be fine.

    It also means that: - You don't need to worry about the PIA itself not being present on the target machine - Any methods or properties which are of the VARIANT type in the original COM interface are now represented using dynamic in your code, which can make your life simpler

    0 讨论(0)
提交回复
热议问题