[New] SaveAs support empty sharedstring #405

This commit is contained in:
WeiLin 2022-06-30 21:50:57 +08:00
parent 7be1bca195
commit 1de30207be
6 changed files with 29 additions and 1 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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>

View File

@ -182,11 +182,13 @@ namespace MiniExcelLibs.OpenXml
{{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)

View File

@ -34,6 +34,20 @@ namespace MiniExcelLibs.Tests
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