Giter VIP home page Giter VIP logo

excel2object's Introduction

Excel2Object

install from nuget release Build status CodeFactor

Excel convert to .NET Object / .NET Object convert to Excel.

Platform

.NET 4.5.2 + .NET Standard 2.0+

NuGet Install

PM> Install-Package Chsword.Excel2Object

Release Notes and roadmap

Features not supported

  • cli tool
  • support auto width column
  • 1. support date datetime time in excel\

Release Notes

  • 2022.03.19
  • 2021.11.4
  • 2021.10.23
  • Nullable DateTime bugfixed @SunBrook
  • 2021.10.22
  • 2021.5.28
  • support style for header & cell, new [ExcelColumnAttribute] for column.
  • support Functions ./ExcelFunctions.md
var list = new List<Pr20Model>
{
        new Pr20Model
        {
            Fullname = "AAA", Mobile = "123456798123"
        },
        new Pr20Model
        {
            Fullname = "BBB", Mobile = "234"
        }
};
var bytes = ExcelHelper.ObjectToExcelBytes(list, ExcelType.Xlsx);
// model
[ExcelTitle("SheetX")]
public class Pr20Model
{
    [ExcelColumn("姓名", CellFontColor = ExcelStyleColor.Red)]
    public string Fullname { get; set; }

    [ExcelColumn("手机",
        HeaderFontFamily = "宋体",
        HeaderBold = true,
        HeaderFontHeight = 30,
        HeaderItalic = true,
        HeaderFontColor = ExcelStyleColor.Blue,
        HeaderUnderline = true,
        HeaderAlignment = HorizontalAlignment.Right,
        //cell
        CellAlignment = HorizontalAlignment.Justify
    )]
    public string Mobile { get; set; }
}
  • v2.0.0.113
convert project to netstandard2.0 and .net452
fixbug #12 #13
  • v1.0.0.80
  • support simple formula
  • support standard excel model
    • excel & JSON convert
    • excel & Dictionary<string,object> convert
Support Uri to a hyperlink cell
And also support text cell to Uri Type
  • v1.0.0.43
Support xlsx [thanks Soar360]
Support complex Boolean type
  • v1.0.0.36
Add ExcelToObject<T>(bytes)

Demo Code

Model

    public class ReportModel
    {
        [Excel("My Title",Order=1)]
        public string Title { get; set; }
        [Excel("User Name",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 ExcelTitleAttribute.

Document

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

Reference

https://github.com/tonyqus/npoi

https://github.com/chsword/ctrc

excel2object's People

Contributors

chsword avatar soar360 avatar oli-bot avatar sunbrook avatar

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.