Skip to content

hahanonym/Excel2Object

 
 

Repository files navigation

Excel2Object

install from nuget downloads release Build status

Excel convert to .NET Object

NuGet Install

PM> Install-Package Chsword.Excel2Object

Release Notes

  • v1.0.0.36

add ExcelToObject(bytes)

Demo Code

Model

    public class ReportModel
    {
        [Excel("标题",Order=1)]
        public string Title { get; set; }
        [Excel("用户",Order=2)]
        public string Name { get; set; }
    }

Model List

      var models = new List<ReportModel>
            {
                new ReportModel{Name="a",Title="b"},
                new ReportModel{Name="c",Title="d"},
                new ReportModel{Name="f",Title="e"}
            };

Convert Object to Excel file.

      var exporter = new ExcelExporter();
      var bytes = exporter.ObjectToExcelBytes(models);
      File.WriteAllBytes("C:\\demo.xls", bytes);

Convert Excel file to Object

      var importer = new ExcelImporter();
      IEnumerable<ReportModel> result = importer.ExcelToObject<ReportModel>("c:\\demo.xls");
      // also can use bytes
      //IEnumerable<ReportModel> result = importer.ExcelToObject<ReportModel>(bytes);

With ASP.NET MVC In ASP.NET MVC Model, DisplayAttribute can be supported like ExcelAttribute.

Document

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

Reference

NPOI https://github.com/tonyqus/npoi

About

Excel convert to .NET Object

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%