Just a simple code for reading an excel file
using System.Data.OleDb;
public void ReadXLS()
{
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Data\Book1.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
OleDbConnection myConnection = new OleDbConnection(connectionString);
try
{
myConnection.Open();
OleDbDataAdapter myAdapter = new OleDbDataAdapter("Select * From [TABLE$]", myConnection);
DataSet dataset = new DataSet();
myAdapter.Fill(dataset);
dataGridView1.DataSource = dataset.Tables[0].DefaultView;
dataset.WriteXml("myxml.xml");
myConnection.Close();
}
catch {}
}
No comments:
Post a Comment