This project has moved. For the latest updates, please go here.

Select multiple columns within Linq

Jan 30, 2012 at 8:36 AM

Is it possible to extract just some columns, but more than one, with LINQ and create a custom collection class.

Something like
"Dim query = from cell in  myworksheet  select new {colum1, colum3,column5}"
 
Thanks

Jan 30, 2012 at 9:52 AM
Edited Jan 30, 2012 at 10:11 AM

It could be easier(f.e. a Rows/Colums property in WorkSheet which returns ExcelRanges), but that should work:

var colums = new int[] { 1, 3, 5 };
var query = from cell in myworksheet.Cells[myworksheet.Dimension.Address]
            join col  in colums
            on cell.Start.Column equals col
            select cell;
Coordinator
Jan 31, 2012 at 5:40 PM
Yes, Rows/Columns properties might be a good idea. 
You can do somthing like this as well to pick out the cells of column 1,3 and 4...
var query = from cell in myworksheet.Cells["A:A,C:D"]