I am using LinqToExcel. I want to be able to get the names of all sheets in an Excel file and compare them with an input value from my html form such that when the input value does not match any of the names on the Excel sheet, the system throws an exception. How do I go about using LinqToExcel to do this?
Asked
Active
Viewed 7,905 times
2 Answers
17
The documentation says:
The GetWorksheetNames() method can be used to retrieve the list of worksheet names in a spreadsheet.
var excel = new ExcelQueryFactory("excelFileName");
var worksheetNames = excel.GetWorksheetNames();

driis
- 161,458
- 45
- 265
- 341
-
Yes i have seen this method but my question is how do i use this to get the list of the sheet names? – plasteezy Aug 29 '11 at 16:54
-
1The method returns the list of sheet names in your Excel file. Is that not what you want ? – driis Aug 29 '11 at 16:55
-
wat syntax should i use to retrieve the sheet names? – plasteezy Aug 29 '11 at 17:04
-
2The worksheetNames variable is an `IEnumerable
`. It contains the names. – driis Aug 29 '11 at 17:09
1
using LinqToExcel;
filename = FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("~/Excelfiles/"+filename));
var xl = new ExcelQueryFactory(Server.MapPath("~/Excelfiles/" + filename));
var worksheetNames = xl.GetWorksheetNames();
DropDownList2.DataSource = worksheetNames;
DropDownList2.DataBind();

bensonissac
- 635
- 5
- 10