read excel file into dataset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I am trying to read an excel file, saved in xml format, into a dataset using
the DataSet.ReadXML() method. When I do this 27 seperate tables are created,
each table describes a different portion of the file (ex. doucument
properties, rows, cells, data, print, etc.) All I want to do is load a
DataGrid with the contents of the excel file, so the user would see the same
thing(columns / rows) as if the file where opened in Excel.
Does anyone have any ideas / suggestions on how to do this?

Thanks,
 
You can oledb datasource to connect to excel sheet

string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
excelPath + ";Extended Properties=Excel 8.0;";

OleDbConnection connection = new OleDbConnection(connectionString);
OleDbDataAdapter adapter = new OleDbDataAdapter("Select * From
[YourSheetName]", connectionString);

DataSet ds = new DataSet();

try
{
connection.Open();

adapter.Fill(ds);

DataGrid1.DataSource = ds.Tables[0];

}


or else you can use the excel objects for more flexible handing.


Its better to use the excel object to read the excel sheets and the load the
data to datatable and bind it to datagrid...
 
Back
Top