Skip to content

Commit

Permalink
#296 使用Json结构导出一个表格的多个区域时,出现格式错乱
Browse files Browse the repository at this point in the history
已复现此问题
  • Loading branch information
xl-wenqiang committed Jul 3, 2021
1 parent 6951a8c commit cc7f88f
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ namespace Magicodes.ExporterAndImporter.Tests
{
public class ExcelTemplateExporter_Tests : TestBase
{
#region 模板导出

[Fact(DisplayName = "Excel模板导出教材订购明细样表(含图片)")]
public async Task ExportByTemplate_Test()
{
Expand Down Expand Up @@ -244,7 +242,6 @@ public async Task DynamicExportWithExpandoObjectByTemplate_Test()
//确保所有的转换均已完成
sheet.Cells[sheet.Dimension.Address].Any(p => p.Text.Contains("{{")).ShouldBeFalse();
}

}

/// <summary>
Expand Down Expand Up @@ -447,7 +444,65 @@ public async Task ShouldUseActualTypeInsteadOfDeclareType_Test()
}
}

#endregion 模板导出
[Fact(DisplayName = "#296")]
public async Task Issue296_Test()
{
string json = @"{
'ReportTitle': '测试报告',
'BeginDate': '2020/06/24',
'EndDate': '2021/06/24',
'播放大厅营收报表': [
{'EquipName':'一区','放映场次':'100','取消场次':1,'售票数量':'100','入场人数':'100','入场异常':'100'},
{'EquipName':'二区','放映场次':'101','取消场次':12,'售票数量':'101','入场人数':'101','入场异常':'101'},
{'EquipName':'三区','放映场次':'101','取消场次':12,'售票数量':'101','入场人数':'101','入场异常':'101'},
{'EquipName':'四区','放映场次':'101','取消场次':12,'售票数量':'101','入场人数':'101','入场异常':'101'},
{'EquipName':'五区','放映场次':'101','取消场次':12,'售票数量':'101','入场人数':'101','入场异常':'101'},
{'EquipName':'六区','放映场次':'101','取消场次':12,'售票数量':'101','入场人数':'101','入场异常':'101'},
{'EquipName':'七区','放映场次':'101','取消场次':12,'售票数量':'101','入场人数':'101','入场异常':'101'},
{'EquipName':'八区','放映场次':'101','取消场次':12,'售票数量':'101','入场人数':'101','入场异常':'101'},
{'EquipName':'九区','放映场次':'101','取消场次':12,'售票数量':'101','入场人数':'101','入场异常':'101'},
],
'播放大厅能耗情况': [
{'EquipName':'一区','放映设备':'100','放映空调':1,'4D设备':'100','能耗异常':'100','冷凝机组':'100','售卖区':'100'},
{'EquipName':'s区','放映设备':'100','放映空调':2,'4D设备':'101','能耗异常':'111','冷凝机组':'200','售卖区':'30'},
{'EquipName':'1区','放映设备':'100','放映空调':2,'4D设备':'101','能耗异常':'111','冷凝机组':'200','售卖区':'30'},
{'EquipName':'一2区','放映设备':'100','放映空调':2,'4D设备':'101','能耗异常':'111','冷凝机组':'200','售卖区':'30'},
{'EquipName':'3','放映设备':'100','放映空调':2,'4D设备':'101','能耗异常':'111','冷凝机组':'200','售卖区':'30'},
{'EquipName':'4','放映设备':'100','放映空调':2,'4D设备':'101','能耗异常':'111','冷凝机组':'200','售卖区':'30'},
{'EquipName':'5','放映设备':'100','放映空调':2,'4D设备':'101','能耗异常':'111','冷凝机组':'200','售卖区':'30'},
{'EquipName':'6','放映设备':'100','放映空调':2,'4D设备':'101','能耗异常':'111','冷凝机组':'200','售卖区':'30'},
{'EquipName':'7','放映设备':'100','放映空调':2,'4D设备':'101','能耗异常':'111','冷凝机组':'200','售卖区':'30'}
],
'安全情况':[
{'EquipName':'火警','时间':'今天','位置':'测试','次数':'100'},
{'EquipName':'异常','时间':'今天','位置':'测试','次数':'100'}
],
'考勤情况':[
{'EquipName':'早班1','出勤':'11','休假':'33','迟到':'55','缺勤':'77','总人数':'1100'},
{'EquipName':'早班2','出勤':'22','休假':'44','迟到':'66','缺勤':'88','总人数':'1100'}
]
}";
var jobj = JObject.Parse(json);
//模板路径
var tplPath = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles", "ExportTemplates",
"ComplexExcel.xlsx");

//创建Excel导出对象
IExportFileByTemplate exporter = new ExcelExporter();
//导出路径
var filePath = Path.Combine(Directory.GetCurrentDirectory(), $"{nameof(Issue296_Test)}.xlsx");
if (File.Exists(filePath)) File.Delete(filePath);

//根据模板导出
await exporter.ExportByTemplate(filePath, jobj, tplPath);

using (var pck = new ExcelPackage(new FileInfo(filePath)))
{
//检查转换结果
var sheet = pck.Workbook.Worksheets.First();
//确保所有的转换均已完成
sheet.Cells[sheet.Dimension.Address].Any(p => p.Text.Contains("{{")).ShouldBeFalse();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<None Update="TestFiles\Errors\数据错误.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestFiles\ExportTemplates\ComplexExcel.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestFiles\ExportTemplates\DynamicExportTpl.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
56 changes: 56 additions & 0 deletions src/Magicodes.ExporterAndImporter.Tests/Models/Export/Issue296.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Magicodes.ExporterAndImporter.Tests.Models.Export
{
public class Issue296
{
public string ReportTitle { get; set; }
public string BeginDate { get; set; }
public string EndDate { get; set; }
public 播放大厅营收报表[] 播放大厅营收报表 { get; set; }
public 播放大厅能耗情况[] 播放大厅能耗情况 { get; set; }
public 安全情况[] 安全情况 { get; set; }
public 考勤情况[] 考勤情况 { get; set; }
}

public class 播放大厅营收报表
{
public string EquipName { get; set; }
public string 放映场次 { get; set; }
public int 取消场次 { get; set; }
public string 售票数量 { get; set; }
public string 入场人数 { get; set; }
public string 入场异常 { get; set; }
}

public class 播放大厅能耗情况
{
public string EquipName { get; set; }
public string 放映设备 { get; set; }
public int 放映空调 { get; set; }
public string _4D设备 { get; set; }
public string 能耗异常 { get; set; }
public string 冷凝机组 { get; set; }
public string 售卖区 { get; set; }
}

public class 安全情况
{
public string EquipName { get; set; }
public string 时间 { get; set; }
public string 位置 { get; set; }
public string 次数 { get; set; }
}

public class 考勤情况
{
public string EquipName { get; set; }
public string 出勤 { get; set; }
public string 休假 { get; set; }
public string 迟到 { get; set; }
public string 缺勤 { get; set; }
public string 总人数 { get; set; }
}
}
Binary file not shown.

0 comments on commit cc7f88f

Please sign in to comment.