Friday, December 4, 2009

Creating and using excel files

Some time ago I have stumbled upon this code fragment:
Dim sConnectionString As String
  sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Book1.xls;Extended Properties=Excel 8.0"
  Dim objConn As New System.Data.OleDb.OleDbConnection(sConnectionString)
  objConn.Open()
  Dim da As New System.Data.OleDb.OleDbDataAdapter("Select * from [Sheet1]", objConn)
  Dim ds As New DataSet("Sheet1")
  da.Fill(ds, "Sheet1") 
In this sample we connect to excel file using jet.oledb driver. I have used this in production and it worked like a charm with extreme preformance. For creating excel files I use excel library. This is probably the best free solution.
Post a Comment