Skip to content

Commit

Permalink
[New] SaveAs support empty sharedstring #405
Browse files Browse the repository at this point in the history
  • Loading branch information
shps951023 committed Jun 30, 2022
1 parent 7be1bca commit 1de3020
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

---

### 1.26.5
- [New] Added DataReader AutoFilter toggle #402 #401 (via @Rollerss)
- [New] SaveAs support empty sharedstring #405

### 1.26.4
- [Bug] Using stream.SaveAs will close the Stream automatically when Specifying excelType
- [OPT] Optimize Query big file _IntMappingAlphabet.Count hot loading count (#400 via @CollapseNav)
Expand Down
4 changes: 4 additions & 0 deletions docs/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

---

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


### 1.26.4
- [Bug] 使用Stream.SaveAs时指定excelType会自动关闭Stream #I57WMM
Expand Down
4 changes: 4 additions & 0 deletions docs/README.zh-Hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

---

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

### 1.26.4
- [Bug] 使用Stream.SaveAs時指定excelType會自動關閉Stream #I57WMM
- [OPT] 減少在讀取大文件時 _IntMappingAlphabet.Count 的調用 (#400 via @CollapseNav)
Expand Down
2 changes: 1 addition & 1 deletion src/MiniExcel/MiniExcelLibs.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net45;netstandard2.0;net5.0</TargetFrameworks>
<Version>1.26.4</Version>
<Version>1.26.5</Version>
</PropertyGroup>
<PropertyGroup>
<AssemblyName>MiniExcel</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,13 @@ static ExcelOpenXmlSheetWriter()
{{format}}
</Relationships>";

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>";
private static string MinifyXml(string xml) => xml.Replace("\r", "").Replace("\n", "").Replace("\t", "");

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

private void CreateZipEntry(string path,string contentType,string content)
Expand Down
14 changes: 14 additions & 0 deletions tests/MiniExcelTests/MiniExcelIssueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ public MiniExcelIssueTests(ITestOutputHelper output)
this.output = output;
}

/// <summary>
/// [SaveAs Support empty sharedstring · Issue #405 · MiniExcel/MiniExcel]
/// (https://github.com/MiniExcel/MiniExcel/issues/405)
/// </summary>
[Fact]
public void TestIssue405()
{
var path = PathHelper.GetTempFilePath();
var value = new[] { new { id = 1, name = "test" } };
MiniExcel.SaveAs(path, value);

var xml = Helpers.GetZipFileContent(path, "xl/sharedStrings.xml");
Assert.StartsWith("<sst xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"", xml);
}

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

0 comments on commit 1de3020

Please sign in to comment.