DotNETWeekly-io / DotNetWeekly

DotNet weekly newsletter
MIT License
198 stars 3 forks source link

【开源项目】ExcelMapper 基于NPOI的Excel实体对象映射库 #653

Closed tonyqus closed 1 month ago

tonyqus commented 1 month ago

https://github.com/mganss/ExcelMapper

一句代码就能从Excel抽取并填充实体list数据 var products = new ExcelMapper("products.xlsx").Fetch<Product>();

gaufung commented 1 month ago

image

ExcelMapper 库可以帮助我们非常方便的从 Excel 中读取数据,并且转换成相应的 POCO 对象集合。比如 Excel 中的数据如下

image

首先定义实体

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());