如何通过 linqtoexcel 从 excel 电子表格的列中找到最大值?

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

我想使用 linqtoexcel.

找到 excel 列的最大值
ColumnA ColumnB
   1       1
   2       4
   3       3

这将 return

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

将您的工作簿列映射到 POCO

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

然后使用 LinqToExcel

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

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