Open XML SDK vs Microsoft.Office.Interop.Excel

As far as I know Microsoft.Office.Interop.Excel needs a Microsoft Offices installed on server machine. That means that you have to buy an Office license. Am I right?

That is correct. In addition, server-side use of Office for automation purposes is not supported. The Office applications were not designed to run without human supervision and have a nasty tendency to “hang” (actually, they’re displaying messages and waiting for user input).

So Open XML or an OLE DB connection would be a preferable approach. I believe both can be used in conjunction with Java, but you might want to visit OpenXMLDeveloper.org for more information about working with the file formats using Java. I’m not sure that Java can use the Open XML SDK, but I believe it can work with “Packages” and certainly with the XML files in the zip “Package” that makes up an Excel workbook.

Neither the Open XML file access (including using the SDK) nor an OLE DB connection requires a license – except for the license for the programming environment (Visual Studio .NET, for example).

“Easy to use” is always a matter of opinion and will depend on the prior experience of the developer… Certainly, it’s a great advantage to understand how the Office application and its files are designed if you use Open XML or the Interop.

What are the main differences between Interop.Excel and Open XML?

The Office Open XML file format allows the developer to work directly with the closed file (*.xlsx, for example). Workbooks can be created from scratch; you can modify existing workbooks.

Interop.Excel enables the developer to interact with the Excel application and, through that, a workbook can be created or modified. Excel.Application is an added layer, which means code execution, generally, will be slower. There’s also the problem with using it server-side, as discussed above.

The one big advantage the Interop has over working directly with the files is that it can dynamically update data. As long as you write pure data to the workbook, you wouldn’t notice any difference. But if you also generate formulas, for example, the workbook won’t open or print with those formulas automatically updated. Either your code would need to perform the calculations and write in the result, or you’d want to run the workbook through Excel Automation Services if you need to have the workbook open fully calculated.


Leave a Reply

Your email address will not be published.