ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to retrieve the activesheet of an Excel file using OleDbConnec (https://www.excelbanter.com/excel-programming/393642-how-retrieve-activesheet-excel-file-using-oledbconnec.html)

leob

How to retrieve the activesheet of an Excel file using OleDbConnec
 
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(OleDbSchemaGui d.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

--
leob


All times are GMT +1. The time now is 01:30 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com