Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Using `Fluent API` to configure POCO excel behaviors, and then provides IEnumera

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

# IMPORTAMT
# IMPORTANT
1. This repo fork from my [NPOI.Extension](https://github.com/xyting/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](https://github.com/xyting/NPOI.Extension) will be and only be fixed by [FluentExcel](https://github.com/Arch/FluentExcel), so, please update your codes use `FluentExcel`.

Expand Down Expand Up @@ -42,6 +42,29 @@ reports.ToExcel(excelFile);
var loadFromExcel = Excel.Load<Report>(excelFile);
```

## Change title cell style
Default title cell style can be changed by using `Excel.Setting.TitleCellStyleApplier`:
```csharp

// 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.
Expand Down
18 changes: 18 additions & 0 deletions samples/FluentExcel.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="NPOI, Version=2.3.0.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.3.0\lib\net40\NPOI.dll</HintPath>
</Reference>
<Reference Include="NPOI.OOXML, Version=2.3.0.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.3.0\lib\net40\NPOI.OOXML.dll</HintPath>
</Reference>
<Reference Include="NPOI.OpenXml4Net, Version=2.3.0.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.3.0\lib\net40\NPOI.OpenXml4Net.dll</HintPath>
</Reference>
<Reference Include="NPOI.OpenXmlFormats, Version=2.3.0.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
<HintPath>..\packages\NPOI.2.3.0\lib\net40\NPOI.OpenXmlFormats.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
Expand All @@ -49,6 +64,9 @@
<Name>FluentExcel</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
17 changes: 17 additions & 0 deletions samples/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using FluentExcel;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using System;
using System.IO;

Expand All @@ -15,6 +17,9 @@ private static void Main(string[] args)
Excel.Setting.For<Report>().FromAnnotations()
.AdjustAutoIndex();

// Change title cell style
//Excel.Setting.TitleCellStyleApplier = MyTitleCellApplier;

var len = 20;
var reports = new Report[len];
for (int i = 0; i < len; i++)
Expand Down Expand Up @@ -116,5 +121,17 @@ private static void FluentConfiguration()
.HasExcelIndex(7)
.HasExcelTitle("收益(元)");
}

private 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);
}
}
}
5 changes: 5 additions & 0 deletions samples/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NPOI" version="2.3.0" targetFramework="net46" />
<package id="SharpZipLib" version="0.86.0" targetFramework="net46" />
</packages>