Question

I am reading an excel file but not all the files have the same column headers but the column order are always the same. I want to read the excel file using linq but not specifying specific column names but could i use just columns based on their order?

var _excelFile = new ExcelQueryFactory(openFileDialog1.FileName);
                var _info = from x in _excelFile.Worksheet()
                            select new
                            {

                            };
Était-ce utile?

La solution

Yea, you can use the WorksheetNoHeader method to refer to columns by their index rather than their name.

Here's an example:

var excel = new ExcelQueryFactory("excelFileName");
var indianaCompanies = from c in excel.WorksheetNoHeader()
                       where c[2] == "IN" //value in 3rd column
                       select c;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top