c#,asp.net-mvc,excel,linq-to-excel
Try this (expanding on @Sachu's comment to the question) - public ActionResult ExcelRead() { string pathToExcelFile = "" + @"C:\MyFolder\ProjectFolder\sample.xlsx"; string sheetName = "Sheet1"; var excelFile = new ExcelQueryFactory(pathToExcelFile); var getData = from a in excelFile.Worksheet(sheetName) select a; string getInfo = String.Empty; foreach (var a in getData) { getInfo +=...
c#,error-handling,iqueryable,linq-to-excel
It may be hard to do even if you will iterate items manually. var enumerator = excel.Worksheet<TmpClass>(...).GetEnumerator(); while (true) { try { if (!enumerator.MoveNext()) break; // use enumerator.Current some way } catch { // you can't use enumerator.Current } } As the exception occurs when calling MoveNext, it's impossible to...
c#,linq,import-from-excel,linq-to-excel
Alternate Solution: I ended up saving the excel sheet as csv file, then import to SQL table.Then i used linq-to-sql to read the data. Root Cause: After researching i found out the problem was that the first cell of this column(web-code) was interger number, and excel trys to figure out...
You can't call a method on a null object, whether it is ToString() or anythig else. if(nameValue[1] != null) { if(nameValue[1].excelValue != null) { return nameValue[1].excelValue.ToString(); } } ...
c#,windows,excel,linq,linq-to-excel
Convert your IEnumerable to DataTable and try this code , int _total = 0; foreach (DataRow _dr in dt.Rows) // Looping Rows { int _value = 0; int _colCount = 1; foreach (var _column in _dr.ItemArray) // Looping Columns { if (_column.ToString() != "") { //if column value is not...
c#,asp.net-mvc,enums,linq-to-excel
The solution was to create a new object and map the property manually. The Enum was handled this way: MyEnumProperty = (MyEnumProperty)Convert.ToInt32(c["ColumnNameInExcel"]) ...