Skip to content

Commit 9d23e32

Browse files
committed
- [New] Query support strict open xml, thanks [Weilence (Lowell)](https://github.com/Weilence) #335
- [New] SaveAs use the configured CultureInfo to write format cell value, thanks [0xced (Cédric Luthi)](https://github.com/0xced) #333 - [New] SaveAsByTemplate will clean template string when parameter is IEnumerable and empty collection. #I4WM67
1 parent 6ae635b commit 9d23e32

File tree

7 files changed

+37
-2
lines changed

7 files changed

+37
-2
lines changed

docs/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
---
1818

1919
### 1.24.0
20+
- [New] Query support strict open xml, thanks [Weilence (Lowell)](https://github.com/Weilence) #335
21+
- [New] SaveAs use the configured CultureInfo to write format cell value, thanks [0xced (Cédric Luthi)](https://github.com/0xced) #333
2022
- [New] SaveAsByTemplate default ignore template missing parameter key exception, OpenXmlConfiguration.IgnoreTemplateParameterMissing can control it. #I4WXFB
23+
- [New] SaveAsByTemplate will clean template string when parameter is IEnumerable and empty collection. #I4WM67
24+
2125

2226
### 1.23.3
2327
- [Bug] SaveAs CSV when value is DataTable, if Key contains `"` then column name will not show `"`。 #I4WDA9

docs/README.zh-CN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
---
2626

2727
### 1.24.0
28+
- [New] Query 支持 strict open xml, 感谢 [Weilence (Lowell)](https://github.com/Weilence) #335
29+
- [New] SaveAs 以自订的 CultureInfo 转换 Format cell 值, 感谢[0xced (Cédric Luthi)](https://github.com/0xced) #333
2830
- [New] SaveAsByTemplate 预设忽略 template 缺少参数 key 错误, OpenXmlConfiguration.IgnoreTemplateParameterMissing 可以开关此卡控. #I4WXFB
31+
- [New] SaveAsByTemplate 当参数集合为空时会清空模版字串. #I4WM67
2932

3033
### 1.23.3
3134
- [Bug] SaveAs CSV 当 value 为 DataTable 时,Key包含双引号Column Name不会显示`"`。 #I4WDA9

docs/README.zh-Hant.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
---
1919

2020
### 1.24.0
21+
- [New] Query 支持 strict open xml, 感謝 [Weilence (Lowell)](https://github.com/Weilence) #335
22+
- [New] SaveAs 以自訂的 CultureInfo 轉換 Format cell 值, 感謝[0xced (Cédric Luthi)](https://github.com/0xced) #333
2123
- [New] SaveAsByTemplate 預設忽略 template 缺少參數 key 錯誤, OpenXmlConfiguration.IgnoreTemplateParameterMissing 可以開關此卡控. #I4WXFB
22-
24+
- [New] SaveAsByTemplate 當參數集合為空時會清空模版字串. #I4WM67
2325

2426
### 1.23.3
2527
- [Bug] SaveAs CSV 當 value 為 DataTable 時,Key包含雙引號Column Name不會顯示`"`。 #I4WDA9

samples/xlsx/TestIssueI4WM67.xlsx

9.42 KB
Binary file not shown.

src/MiniExcel/MiniExcelLibs.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>net45;netstandard2.0;net5.0</TargetFrameworks>
4-
<Version>1.23.2</Version>
4+
<Version>1.24.0</Version>
55
</PropertyGroup>
66
<PropertyGroup>
77
<AssemblyName>MiniExcel</AssemblyName>

src/MiniExcel/OpenXml/ExcelOpenXmlTemplate.Impl.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,12 @@ private void UpdateDimensionAndGetRowsInfo(Dictionary<string, object> inputMaps,
526526
//TODO: check if not contain 1 index
527527
//only check first one match IEnumerable, so only render one collection at same row
528528

529+
// Empty collection parameter will get exception https://gitee.com/dotnetchina/MiniExcel/issues/I4WM67
530+
if (xRowInfo.PropsMap == null)
531+
{
532+
v.InnerText = v.InnerText.Replace($"{{{{{propNames[0]}}}}}", propNames[1]);
533+
break;
534+
}
529535
// auto check type https://github.com/shps951023/MiniExcel/issues/177
530536
var prop = xRowInfo.PropsMap[propNames[1]];
531537
var type = prop.UnderlyingTypePropType; //avoid nullable

tests/MiniExcelTests/MiniExcelIssueTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ public MiniExcelIssueTests(ITestOutputHelper output)
3131
this.output = output;
3232
}
3333

34+
[Fact]
35+
public void TestIssueI4WM67()
36+
{
37+
var path = PathHelper.GetTempFilePath();
38+
var templatePath = PathHelper.GetFile("xlsx/TestIssueI4WM67.xlsx");
39+
var value = new Dictionary<string, object>()
40+
{
41+
["users"] = new TestIssueI4WM67Dto[]{ }
42+
};
43+
MiniExcel.SaveAsByTemplate(path, templatePath, value);
44+
var rows = MiniExcel.Query(path).ToList();
45+
Assert.Single(rows);
46+
}
47+
48+
public class TestIssueI4WM67Dto
49+
{
50+
public int ID { get; set; }
51+
public string Name { get; set; }
52+
}
53+
3454
[Fact]
3555
public void TestIssueI4WXFB()
3656
{

0 commit comments

Comments
 (0)