How to retrieve the activesheet of an Excel file using OleDbConnec

L

leob

I need to retrieve the the active worksheet of an Excel file using
OleDbConnection.

With the following code, I can retrieve the list worksheets, but I can't
find a way to get to the active one.

string sExcelFileName = @"c:\excelfiles\ExcelFile.xls";
string sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ sExcelFileName + ";Extended Properties=\"Excel 8.0;HDR=No;IMEX=1;\"";
OleDbConnection ExcelConnection = new OleDbConnection(sConnectionString);
ExcelConnection.Open();
DataTable excelDataTable =
ExcelConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[]
{null, null});
foreach (DataRow row in excelDataTable.Rows)
{
string sWorksheetName = row["TABLE_NAME"].ToString();
MessageBox.Show(sWorksheetName);
}
ExcelConnection.Close();


More generally, I need to access the content of the active worksheet of an
excel file submitted to an ASP .NET web application.
Any way of doing it without using directly server-side automation of Office?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top