Optimal way to Read an Excel file (.xls/.xlsx)

后端 未结 7 1817
一生所求
一生所求 2020-11-27 12:01

I know that there are different ways to read an Excel file:

  • Iterop
  • Oledb
  • Open Xml SDK

C

7条回答
  •  广开言路
    2020-11-27 12:35

    Take a look at Linq-to-Excel. It's pretty neat.

    var book = new LinqToExcel.ExcelQueryFactory(@"File.xlsx");
    
    var query =
        from row in book.Worksheet("Stock Entry")
        let item = new
        {
            Code = row["Code"].Cast(),
            Supplier = row["Supplier"].Cast(),
            Ref = row["Ref"].Cast(),
        }
        where item.Supplier == "Walmart"
        select item;
    

    It also allows for strongly-typed row access too.

提交回复
热议问题