How convert Excel data into DataSet/DataTable?

  • Thread starter Thread starter Ronald S. Cook
  • Start date Start date
R

Ronald S. Cook

Hi,

I need to open an Excel file from within my ASP.NET app and read data. I'm
guessing the most like format in ASP.NET would be a DataTable.

Regardles,, how do I get the data into my ASP.NET app from the Excel file?
I have made a reference to the Excel 11.0 object library, but am not sure
what code comes next.

Thanks,
Ron
 
Ron,
As long as the data in the Sheet is tabular, you would probably be better
off just using an OleDb JET connection string directly to the Excel workbook
and reading in the data with ADO.NET

Excel with Interop is extremely messy on an IIS webserver.

There are a number of samples around, I just don't have one handy.
Peter
 
Hello Ronald,

Use OLE DB Jet provider to access data stored in Excel.
connection string looks like: Provider=Microsoft.Jet.OLEDB.4.0;Data Source=myBook.xls;Extended
Properties="Excel 8.0;HDR=YES";

Then use

OleDbDataAdapter da;
da = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString);

after that u Fill dataset and use it in your ASP.net page

I recomend to get data in XML format, coz it's easy to trasnsorm them in
suitable form for page using XSLT


RC> I need to open an Excel file from within my ASP.NET app and read
RC> data. I'm guessing the most like format in ASP.NET would be a
RC> DataTable.
RC>
RC> Regardles,, how do I get the data into my ASP.NET app from the Excel
RC> file? I have made a reference to the Excel 11.0 object library, but
RC> am not sure what code comes next.
RC>
RC> Thanks,
RC> Ron
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Back
Top