.NET, OleDB and Excel

OleDB is a very useful API in .NET, especially when programmatically manipulating the data in an Excel spreadsheet. In fact, it can open an Excel spreadsheet and query the data using regular SQL statements.

using System.Data.OleDb;
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=somedataineed.xls;Extended Properties=\"Excel 12.0 Xml;HDR=NO\";");

The connection string is fairly standard. However, notice the ‘HDR=No’ under extended properties, this tells the connection to assume that the first row does not contain header text. By default, or if ‘HDR=Yes’, the first row will be disregarded as headers and the first row of data may be skipped, be CAREFUL.
Continue reading