Giter Club home page Giter Club logo

excel2object's Introduction

Excel2Object

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

博客说明

http://www.cnblogs.com/chsword/p/excel2object.html

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.