This project has moved and is read-only. For the latest updates, please go here.

Select multiple columns within Linq

Jan 30, 2012 at 9: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}"

Jan 30, 2012 at 10:52 AM
Edited Jan 30, 2012 at 11: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;
Jan 31, 2012 at 6: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"]