问题
I am using LinqToExcel and i want to be able to get the names of all sheets in an excel file and compare it with an input from my html form such that when the input does not match any of the names on the excel sheet the system will throw an exception. How do i go about using LinqToExcel to do this
回答1:
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();
回答2:
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();
来源:https://stackoverflow.com/questions/7232960/how-do-i-use-linqtoexcel-to-get-sheet-names-of-an-excel-file