XLS import [modified]
-
Hi all How i can read xls file with out using standard COM library of Excel(Microsoft Excel x.0 Object Library), because it work very slow. I try to export data from XLS file to XML file first and after read this XML file, but unfotunately Excel 9.0 library has not this functionality. Any idea please. -- modified at 9:22 Thursday 29th November, 2007
-
Hi all How i can read xls file with out using standard COM library of Excel(Microsoft Excel x.0 Object Library), because it work very slow. I try to export data from XLS file to XML file first and after read this XML file, but unfotunately Excel 9.0 library has not this functionality. Any idea please. -- modified at 9:22 Thursday 29th November, 2007
Dear Friend, Hi. ;P string strFileName = "fileName.xls"; System.Data.OleDb.OleDbConnection excelConn = new System.Data.OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source= '" + strFileName + "'; " + " extended properties=excel 8.0;"); string strsql = "Select * from [Sheet1$]"; System.Data.OleDb.OleDbDataAdapter excelDataAdap = new System.Data.OleDb.OleDbDataAdapter(strsql, excelConn); dsExcel = new DataSet(); if (excelConn.State == ConnectionState.Closed) { excelConn.Open(); } //Select the values from Excel excelDataAdap.Fill(dsExcel); GridView1.DataSource = dsExcel; GridView1.DataBind(); System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand(strsql, excelConn); System.Data.OleDb.OleDbDataReader dr = cmd.ExecuteReader(); string sqlConnectionString = "Data Source=srvr;Initial Catalog=db;User Id=usr;Password=pwd"; // Bulk Copy to SQL Server System.Data.SqlClient.SqlBulkCopy bulkCopy = new System.Data.SqlClient.SqlBulkCopy(sqlConnectionString); bulkCopy.DestinationTableName = "ExcelData"; bulkCopy.WriteToServer(dr); I hope this will helps u.....
"Good Thing Goes With Good People..."