Excel 与 Object 互相转换
使用的NPOI
https://github.com/tonyqus/npoi
Demo Code 前提 准备一个Model
public class ReportModel
{
[Excel("标题",Order=1)]
public string Title { get; set; }
[Excel("用户",Order=2)]
public string Name { get; set; }
}
准备一个List
var models = new List<ReportModel>
{
new ReportModel{Name="a",Title="b"},
new ReportModel{Name="c",Title="d"},
new ReportModel{Name="f",Title="e"}
};
由Object转为Excel
var exporter = new ExcelExporter();
var bytes = exporter.ObjectToExcelBytes(models);
File.WriteAllBytes("C:\\demo.xls", bytes);
由Excel转为Object
var importer = new ExcelImporter();
IEnumerable<ReportModel> result = importer.ExcelToObject<ReportModel>("c:\\demo.xls");
与ASP.NET MVC结合使用 由于ASP.NET MVC中Model上会使用DisplayAttribute所以Excel2Object除了支持ExcelAttribute外,也支持DisplayAttribute。
.NET 项目中使用 使用NuGet安装即可,命令行安装
Install-Package Chsword.Excel2Object
或搜索包
Chsword.Excel2Object
博客说明
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.