Skip to content

Commit

Permalink
fix: fix the merge cell behaviors issues when the value isn't string.
Browse files Browse the repository at this point in the history
  • Loading branch information
rigofunc committed Jun 21, 2017
1 parent e5608fa commit b1289c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The first two features will be very useful for English not their mother language

## Configure model's excel behaviors

We can use `fluent api` or `attributes` to configure the model excel behaviors.
We can use `fluent api` or `attributes` to configure the model excel behaviors. If both had been used, `fluent` configurations will has the `Hight Priority`

### 1. Use Fluent Api

Expand All @@ -41,45 +41,45 @@ We can use `fluent api` or `attributes` to configure the model excel behaviors.
/// <summary>
/// Use fluent configuration api. (doesn't poison your POCO)
/// </summary>
static void ExcelFluentConfig()
static void FluentConfiguration()
{
var mc = Excel.Setting.For<Report>();
var fc = Excel.Setting.For<Report>();

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

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

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

mc.Property(r => r.HandleTime)
fc.Property(r => r.HandleTime)
.HasExcelIndex(2)
.HasExcelTitle("成交时间");

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

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

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

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

mc.Property(r => r.Profits)
fc.Property(r => r.Profits)
.HasExcelIndex(7)
.HasExcelTitle("收益(元)");
}
Expand Down
9 changes: 3 additions & 6 deletions src/Extensions/IEnumerableNpoiExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,14 @@ internal static IWorkbook ToWorkbook<T>(this IEnumerable<T> source, string excel
continue;
}

var previous = "";
//object previous = null;
object previous = null;
int rowspan = 0, row = 1;
if (config.AllowMerge)
{
for (row = 1; row < rowIndex; row++)
{
var value = sheet.GetRow(row).Cells[config.Index].StringCellValue;
if (previous == value && !string.IsNullOrEmpty(value))
//var value = sheet.GetRow(row).GetCellValue(config.Index);
//if (previous == value && value != null)
var value = sheet.GetRow(row).GetCellValue(config.Index);
if (object.Equals(previous, value) && value != null)
{
rowspan++;
}
Expand Down

0 comments on commit b1289c0

Please sign in to comment.