All Projects → Arch → FluentExcel

Arch / FluentExcel

Licence: Apache-2.0 license
Use Fluent API to configure POCO excel behaviors, and then provides IEnumerable<T> has save to and load from excel functionalities.

Projects that are alternatives of or similar to FluentExcel

Npoi
A .NET library for reading and writing Microsoft Office binary and OOXML file formats.
Stars: ✭ 1,751 (+2298.63%)
Mutual labels:  excel, npoi
Npoi.extension
This repo contains the extension for the NPOI, which provides IEnumerable<T> have save to and load from excel functionalities.
Stars: ✭ 67 (-8.22%)
Mutual labels:  excel, fluent
Excel-to-JSON
Excel add-in converting excel to json
Stars: ✭ 15 (-79.45%)
Mutual labels:  excel
MediaFlyout
Windows 10+ Media Control Taskbar Flyout
Stars: ✭ 87 (+19.18%)
Mutual labels:  fluent
office-addin-react
To help you learn to use Office.js and React build an Excel add-in
Stars: ✭ 46 (-36.99%)
Mutual labels:  excel
Sylvan.Data.Excel
The fastest .NET library for reading Excel data files.
Stars: ✭ 65 (-10.96%)
Mutual labels:  excel
luban
你的最佳游戏配置解决方案 {excel, csv, xls, xlsx, json, bson, xml, yaml, lua, unity scriptableobject} => {json, bson, xml, lua, yaml, protobuf(pb), msgpack, flatbuffers, erlang, custom template} data + {c++, java, c#, go(golang), lua, javascript(js), typescript(ts), erlang, rust, gdscript, protobuf schema, flatbuffers schema, custom template} code。
Stars: ✭ 1,660 (+2173.97%)
Mutual labels:  excel
angular-odata-es5
OData Service for Angular.io (es5 version)
Stars: ✭ 45 (-38.36%)
Mutual labels:  fluent
Spreadsheet Excel Writer
Allows writing of Excel spreadsheets. Since 2002.
Stars: ✭ 42 (-42.47%)
Mutual labels:  excel
paginator
Offset pagination for Vapor 🗂
Stars: ✭ 67 (-8.22%)
Mutual labels:  fluent
xls2db
Export table data from excel to mysql database, implemented with python.
Stars: ✭ 33 (-54.79%)
Mutual labels:  excel
spreadsheet
TypeScript/javascript spreadsheet parser, with formulas.
Stars: ✭ 40 (-45.21%)
Mutual labels:  excel
laravel-xlswriter
an excel export/import tool for laravel based on php-xlswriter
Stars: ✭ 54 (-26.03%)
Mutual labels:  excel
fluent-mysql-driver
🖋🐬 Swift ORM (queries, models, relations, etc) built on MySQL.
Stars: ✭ 69 (-5.48%)
Mutual labels:  fluent
sense-export
Just a simple button to export data in your Qlik Sense applications.
Stars: ✭ 28 (-61.64%)
Mutual labels:  excel
Power-Query-Excel-Formats
A collection of M code to get various formats from Excel sheets in Power Query
Stars: ✭ 43 (-41.1%)
Mutual labels:  excel
json2xls
{"generate excel by json data": "根据json数据生成Excel表格"}
Stars: ✭ 30 (-58.9%)
Mutual labels:  excel
web-pivot-table
A feature-rich JS pivot grid library for creating interactive reports. Integrates with any front-end technology
Stars: ✭ 35 (-52.05%)
Mutual labels:  excel
website
Fully responsive website built with NextJS, React and Fluent UI, with the aim of providing services and access to all groups of didactic courses and general purposes to students of the University of Milan.
Stars: ✭ 29 (-60.27%)
Mutual labels:  fluent
exceltricks
My commonly used Excel and Google Sheet formulas and tricks
Stars: ✭ 87 (+19.18%)
Mutual labels:  excel

Using Fluent API to configure POCO excel behaviors, and then provides IEnumerable<T> has save to and load from excel functionalities.

Features

  • Decouple the configuration from the POCO model by using fluent api.
  • Support none configuration POCO, so that if English is your mother language, none any more configurations;

The first features will be very useful for English not their mother language developers.

IMPORTANT

  1. This repo fork from my NPOI.Extension, and remove all the attributes based features (but can be extended, see the following demo), and will only support Fluent API.
  2. All the issues found in NPOI.Extension will be and only be fixed by FluentExcel, so, please update your codes use FluentExcel.

Overview

FluentExcel demo

Get Started

The following demo codes come from sample, download and run it for more information.

Install FluentExcel package

    PM> Install-Package FluentExcel

Using FluentExcel in code

    using FluentExcel;

Saving IEnumerable<T> to excel.

var excelFile = @"/Users/rigofunc/Documents/sample.xlsx";

// save to excel file
reports.ToExcel(excelFile);

Loading IEnumerable<T> from excel.

// load from excel
var loadFromExcel = Excel.Load<Report>(excelFile);       

Change title cell style

Default title cell style can be changed by using Excel.Setting.TitleCellStyleApplier:

// Center, Green background, White font color
static void MyTitleCellApplier(ICellStyle cellStyle, IFont font)
{
    cellStyle.Alignment = HorizontalAlignment.Center;
    cellStyle.VerticalAlignment = VerticalAlignment.Center;
            
    cellStyle.FillPattern = FillPattern.SolidForeground;
    cellStyle.FillForegroundColor = HSSFColor.Green.Index;

    font.Color = HSSFColor.White.Index;
    cellStyle.SetFont(font);
}

[...]

Excel.Setting.TitleCellStyleApplier = MyTitleCellApplier;
reports.ToExcel(excelFile);

Use Fluent Api to configure POCO's excel behaviors

We can use fluent api to configure the model excel behaviors.

/// <summary>
/// Use fluent configuration api. (doesn't poison your POCO)
/// </summary>
static void FluentConfiguration()
{
    var fc = Excel.Setting.For<Report>();

    fc.HasStatistics("合计", "SUM", 6, 7)
      .HasFilter(firstColumn: 0, lastColumn: 2, firstRow: 0)
      .HasFreeze(columnSplit: 2, rowSplit: 1, leftMostColumn: 2, topMostRow: 1);

    fc.Property(r => r.City)
      .HasExcelIndex(0)
      .HasExcelTitle("城市")
      .IsMergeEnabled();

    // or
    //fc.Property(r => r.City).HasExcelCell(0,"城市", allowMerge: true);

    fc.Property(r => r.Building)
      .HasExcelIndex(1)
      .HasExcelTitle("楼盘")
      .IsMergeEnabled();

    // configures the ignore when exporting or importing.
    fc.Property(r => r.Area)
      .HasExcelIndex(8)
      .HasExcelTitle("Area")
      .IsIgnored(exportingIsIgnored: false, importingIsIgnored: true);

    // or
    //fc.Property(r => r.Area).IsIgnored(8, "Area", formatter: null, exportingIsIgnored: false, importingIsIgnored: true);

    fc.Property(r => r.HandleTime)
      .HasExcelIndex(2)
      .HasExcelTitle("成交时间")
      .HasDataFormatter("yyyy-MM-dd");

    // or 
    //fc.Property(r => r.HandleTime).HasExcelCell(2, "成交时间", formatter: "yyyy-MM-dd", allowMerge: false);
    // or
    //fc.Property(r => r.HandleTime).HasExcelCell(2, "成交时间", "yyyy-MM-dd");


    fc.Property(r => r.Broker)
      .HasExcelIndex(3)
      .HasExcelTitle("经纪人");

    fc.Property(r => r.Customer)
      .HasExcelIndex(4)
      .HasExcelTitle("客户");

    fc.Property(r => r.Room)
      .HasExcelIndex(5)
      .HasExcelTitle("房源");

    fc.Property(r => r.Brokerage)
      .HasExcelIndex(6)
      .HasDataFormatter("¥0.00")
      .HasExcelTitle("佣金(元)");

    fc.Property(r => r.Profits)
      .HasExcelIndex(7)
      .HasExcelTitle("收益(元)");
}
class Program
{
    static void Main(string[] args)
    {
        // global call this
        FluentConfiguration();

        // demo the extension point
        //var fc = Excel.Setting.For<Report>().FromAnnotations();

        var len = 20;
        var reports = new Report[len];
        for (int i = 0; i < len; i++)
        {
            reports[i] = new Report
            {
                City = "ningbo",
                Building = "世茂首府",
                HandleTime = DateTime.Now,
                Broker = "rigofunc 18957139**7",
                Customer = "yingting 18957139**7",
                Room = "2#1703",
                Brokerage = 125 * i,
                Profits = 25 * i
            };
        }

        var excelFile = @"/Users/rigofunc/Documents/sample.xlsx";

        // save to excel file
        reports.ToExcel(excelFile);

        // load from excel
        var loadFromExcel = Excel.Load<Report>(excelFile);
    }
}

EXTENSIONS/CUSTOMIZING DEMO: From Annotations by extenstion methods.

Excel.Setting.For<Report>().FromAnnotations()
                           .AdjustAutoIndex();

The following demo show how to extend the exist functionalities by extension methods.

1. Applying annotations to the specified model

public class Report
{
    [Display(Name = "城市")]
    public string City { get; set; }
    [Display(Name = "楼盘")]
    public string Building { get; set; }
    [Display(Name = "区域")]
    public string Area { get; set; }
    [Display(Name = "成交时间")]
    public DateTime HandleTime { get; set; }
    [Display(Name = "经纪人")]
    public string Broker { get; set; }
    [Display(Name = "客户")]
    public string Customer { get; set; }
    [Display(Name = "房源")]
    public string Room { get; set; }
    [Display(Name = "佣金(元)")]
    public decimal Brokerage { get; set; }
    [Display(Name = "收益(元)")]
    public decimal Profits { get; set; }
}

2. Defines the extension methods.

public static class FluentConfigurationExtensions
{
    public static FluentConfiguration<TModel> FromAnnotations<TModel>(this FluentConfiguration<TModel> fluentConfiguration) where TModel : class
    {
        var properties = typeof(TModel).GetProperties();
        foreach (var property in properties)
        {
            var pc = fluentConfiguration.Property(property);

            var display = property.GetCustomAttribute<DisplayAttribute>();
            if (display != null)
            {
                pc.HasExcelTitle(display.Name);
                if (display.GetOrder().HasValue)
                {
                    pc.HasExcelIndex(display.Order);
                }
            }
            else
            {
                pc.HasExcelTitle(property.Name);
            }

            var format = property.GetCustomAttribute<DisplayFormatAttribute>();
            if (format != null)
            {
                pc.HasDataFormatter(format.DataFormatString
                                          .Replace("{0:", "")
                                          .Replace("}", ""));
            }

            if (pc.Index < 0)
            {
                pc.HasAutoIndex();
            }
        }

        return fluentConfiguration;
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].