Skip to content

Commit

Permalink
feat: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rigofunc committed Sep 21, 2017
1 parent e2ee920 commit 9bda621
Showing 1 changed file with 102 additions and 99 deletions.
201 changes: 102 additions & 99 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ The first features will be very useful for English not their mother language dev

The following demo codes come from [sample](samples), download and run it for more information.

## Using Package Manager Console to install FluentExcel
## Install FluentExcel package

PM> Install-Package FluentExcel

## Reference FluentExcel in code
## Using FluentExcel in code

using FluentExcel;

Expand All @@ -42,14 +42,16 @@ reports.ToExcel(excelFile);
var loadFromExcel = Excel.Load<Report>(excelFile);
```

# From Annotations by extenstion methods.
## From Annotations by extenstion methods.

```csharp
var fc = Excel.Setting.For<Report>().FromAnnotations();
var fluentConfiguration = Excel.Setting.For<Report>().FromAnnotations();
```

The following demo show how to extend the exist functionalities by extension methods. `NOTE:` the initial idea from @tupunco.

### Applying the annotations to the model

```csharp
public class Report
{
Expand All @@ -74,7 +76,7 @@ public class Report
}
```

Defines the extension methods.
### Defines the extension methods.

```csharp
public static class FluentConfigurationExtensions
Expand Down Expand Up @@ -124,107 +126,108 @@ public static class FluentConfigurationExtensions
We can use `fluent api` to configure the model excel behaviors.

```csharp
using System;
using FluentExcel;

namespace samples
/// <summary>
/// Use fluent configuration api. (doesn't poison your POCO)
/// </summary>
static void FluentConfiguration()
{
class Program
{
static void Main(string[] args)
{
// global call this
FluentConfiguration();
var fc = Excel.Setting.For<Report>();

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
};
}
fc.HasStatistics("合计", "SUM", 6, 7)
.HasFilter(firstColumn: 0, lastColumn: 2, firstRow: 0)
.HasFreeze(columnSplit: 2, rowSplit: 1, leftMostColumn: 2, topMostRow: 1);

var excelFile = @"/Users/rigofunc/Documents/sample.xlsx";
fc.Property(r => r.City)
.HasExcelIndex(0)
.HasExcelTitle("城市")
.IsMergeEnabled();

// save to excel file
reports.ToExcel(excelFile);
// or
//fc.Property(r => r.City).HasExcelCell(0,"城市", allowMerge: true);
// load from excel
var loadFromExcel = Excel.Load<Report>(excelFile);
}
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("客户");

/// <summary>
/// Use fluent configuration api. (doesn't poison your POCO)
/// </summary>
static void FluentConfiguration()
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("收益(元)");
}
```

```csharp
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++)
{
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);

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)
// the formatter is Excel formatter, not the C# formatter
.HasDataFormatter("¥0.00")
.HasExcelTitle("佣金(元)");

fc.Property(r => r.Profits)
.HasExcelIndex(7)
.HasExcelTitle("收益(元)");
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);
}
}
}
```

0 comments on commit 9bda621

Please sign in to comment.