How to find max value by linqtoexcel from the column(s) of excel spreadsheet?

128 Views Asked by At

I would like to find maximum value(s) of excel column(s) by using linqtoexcel.

ColumnA ColumnB
   1       1
   2       4
   3       3

which will return

"max ColumnA is 3" "max ColumnB is 4"

1

There are 1 best solutions below

0
Greg On BEST ANSWER

Map your workbook columns to POCO

public class WorkSheetClass
{
    public int ColumnA { get; set; }
    public int ColumnB { get; set; }
}

then using LinqToExcel

string pathToExcelFile = @"C:\workbook1.xlsx";
string workbookName = "workbook1";

var columnAMaxValue = new ExcelQueryFactory(pathToExcelFile)
                              .Worksheet<WorkSheetClass>(workbookName)
                              .Max(x => x.ColumnA);