Closed tonyqus closed 1 month ago
ExcelMapper
库可以帮助我们非常方便的从 Excel 中读取数据,并且转换成相应的 POCO 对象集合。比如 Excel 中的数据如下
首先定义实体
class Product
{
public string Name { get; set; }
[Column("Number")]
public int NumberInStock { get; set;}
public decimal Price { get; set; }
}
使用 Fetch
方法获取对象集合
using Ganss.Excel;
var products = new ExcelMapper("Product.xlsx").Fetch<Product>();
System.Console.WriteLine(products.Count());
https://github.com/mganss/ExcelMapper
一句代码就能从Excel抽取并填充实体list数据
var products = new ExcelMapper("products.xlsx").Fetch<Product>();