How do i use LinqToExcel to get sheet names of an excel file

情到浓时终转凉″ 提交于 2019-12-12 11:44:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!