Blogger D

Blogging for fun and no profit.

« PreviousNext »

EntLib Data Access Block and Excel

10 October 2007

I need to be able to open an Excel workbook and grab the data from one of the worksheets. I don't want to use any Office InterOperability (as that sucks) and I know I can do it using ADO.Net. But since 1.) I hate writing all of that DataAdapter / Connection code because 2.) I am lazy I decided to see how hard it would be to use the EntLib DAB.

Turned out it was pretty easy.

Create your configuration as such:

Then call your code as such:

PLAIN TEXT
C#:
  1. public static DataSet GetWorksheet()
  2. {
  3. string sql = "SELECT * FROM [Sheet1$]";
  4. string connectionName = "Book1";
  5.  
  6. return DatabaseFactory.CreateDatabase(connectionName)
  7. .ExecuteDataSet(CommandType.Text, sql);
  8. }

And that is that. One DataSet ready to go.

Posted in General | | Top Of Page

Comments are closed.