Skip to content

Commit 1de3020

Browse files
committed
[New] SaveAs support empty sharedstring #405
1 parent 7be1bca commit 1de3020

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

docs/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
---
2424

25+
### 1.26.5
26+
- [New] Added DataReader AutoFilter toggle #402 #401 (via @Rollerss)
27+
- [New] SaveAs support empty sharedstring #405
28+
2529
### 1.26.4
2630
- [Bug] Using stream.SaveAs will close the Stream automatically when Specifying excelType
2731
- [OPT] Optimize Query big file _IntMappingAlphabet.Count hot loading count (#400 via @CollapseNav)

docs/README.zh-CN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
---
2727

28+
### 1.26.5
29+
- [New] Added DataReader AutoFilter toggle #402 #401 (via @Rollerss)
30+
- [New] SaveAs 支持空白 sharedstring #405
31+
2832

2933
### 1.26.4
3034
- [Bug] 使用Stream.SaveAs时指定excelType会自动关闭Stream #I57WMM

docs/README.zh-Hant.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
---
2626

27+
### 1.26.5
28+
- [New] Added DataReader AutoFilter toggle #402 #401 (via @Rollerss)
29+
- [New] SaveAs 支持空白 sharedstring #405
30+
2731
### 1.26.4
2832
- [Bug] 使用Stream.SaveAs時指定excelType會自動關閉Stream #I57WMM
2933
- [OPT] 減少在讀取大文件時 _IntMappingAlphabet.Count 的調用 (#400 via @CollapseNav)

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.26.4</Version>
4+
<Version>1.26.5</Version>
55
</PropertyGroup>
66
<PropertyGroup>
77
<AssemblyName>MiniExcel</AssemblyName>

src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.DefualtOpenXml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,13 @@ static ExcelOpenXmlSheetWriter()
182182
{{format}}
183183
</Relationships>";
184184

185+
private static readonly string _defaultSharedString = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" count=\"0\" uniqueCount=\"0\"></sst>";
185186
private static string MinifyXml(string xml) => xml.Replace("\r", "").Replace("\n", "").Replace("\t", "");
186187

187188
internal void GenerateDefaultOpenXml()
188189
{
189190
CreateZipEntry("_rels/.rels", "application/vnd.openxmlformats-package.relationships+xml", ExcelOpenXmlSheetWriter._defaultRels);
191+
CreateZipEntry("xl/sharedStrings.xml", "application/vnd.openxmlformats-package.relationships+xml", ExcelOpenXmlSheetWriter._defaultSharedString);
190192
}
191193

192194
private void CreateZipEntry(string path,string contentType,string content)

tests/MiniExcelTests/MiniExcelIssueTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ public MiniExcelIssueTests(ITestOutputHelper output)
3434
this.output = output;
3535
}
3636

37+
/// <summary>
38+
/// [SaveAs Support empty sharedstring · Issue #405 · MiniExcel/MiniExcel]
39+
/// (https://github.com/MiniExcel/MiniExcel/issues/405)
40+
/// </summary>
41+
[Fact]
42+
public void TestIssue405()
43+
{
44+
var path = PathHelper.GetTempFilePath();
45+
var value = new[] { new { id = 1, name = "test" } };
46+
MiniExcel.SaveAs(path, value);
47+
48+
var xml = Helpers.GetZipFileContent(path, "xl/sharedStrings.xml");
49+
Assert.StartsWith("<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"", xml);
50+
}
3751

3852
/// <summary>
3953
/// Using stream.SaveAs will close the Stream automatically when Specifying excelType

0 commit comments

Comments
 (0)