Reputation: 912
I want to read to my WEBApplication excel file, I found a way to do it with connection string the problem is that i don't spouse to know the work sheet amount and names. moreover, i want to use this names in DropDownList to give the user the ability to choose one.
Upvotes: 0
Views: 14946
Reputation: 57573
If in your project you set a reference to assembly Microsoft.Office.Interop.Excel
you can read your Excel file and use all functions you need.
EDITED after user comment:
public void Read(string filename)
{
Excel.Application excel = new Excel.Application();
Excel.Workbook wb = excel.Workbooks.Open(filename);
// Get worksheet names
foreach (Excel.Worksheet sh in wb.Worksheets)
Debug.WriteLine(sh.Name);
// Get values from sheets SH1 and SH3 (in my file)
object val1 = wb.Sheets["SH1"].Cells[1, "A"].Value2;
object val3 = wb.Sheets["SH3"].Cells[1, "A"].Value2;
Debug.WriteLine("{0} / {1}", val1, val3);
wb.Close();
excel.Quit();
}
Upvotes: 9
Reputation: 386
Take a look at the OLE DB provider for Jet. http://msdn.microsoft.com/en-us/library/ms175866.aspx
Upvotes: 0