What options do I have for reading Excel files from my C# code?
Posted: (EET/GMT+2)
A project I'm working on required me to periodically import data from an Excel spreadsheet into an SQL Server database. I wanted to do this as easily as possible, so I needed to ponder which one of the methods available do the job best.
This leads to the question: which methods can I use to read Excel workbooks, either in traditional XLS or the newer XML-based XSLX files? Unless you count third-party solutions in, there are two basic methods: using OLEDB/ADO drivers, or, in case of XLSX files, you can use the Open XML SDK library to process Excel files based on their XML format.
Microsoft has written Knowledge Base support articles about using ADO, and the Open XML SDK documentation provides examples on using that library.
Which one did I pick? Since I already had plenty of code in place to work with XLSX files using the Open XML SDK, this was my choice for an ASP.NET web application. But, had I had the need to import the data from, say, within an SQL Server stored procedure, using ADO would have been a better choice.
Hope this helps!