Skip to content

Commit 57751a2

Browse files
committed
[Bug] Fix SaveAs multiple sheet value error "Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded." #325
1 parent 67eddb9 commit 57751a2

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
---
1818

19+
### 0.21.5
20+
- [Bug] Fix SaveAs multiple sheet value error "Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded." #325
21+
1922
### 0.21.4
2023
- [New] Remove LISENCE_CODE check
2124

docs/README.zh-CN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
---
2525

26+
### 0.21.5
27+
- [Bug] 修正 SaveAs multiple sheet value error "Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded." #325
28+
2629
### 0.21.4
2730
- [New] Remove LISENCE_CODE check
2831

docs/README.zh-Hant.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
---
1919

20+
### 0.21.5
21+
- [Bug] 修正 SaveAs multiple sheet value error "Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded." #325
22+
2023
### 0.21.4
2124
- [New] Remove LISENCE_CODE check
2225

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>0.21.4</Version>
4+
<Version>0.21.5</Version>
55
</PropertyGroup>
66
<PropertyGroup>
77
<AssemblyName>MiniExcel</AssemblyName>

src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ private void GenerateEndXml()
637637
{
638638
var workbookXml = new StringBuilder();
639639
var workbookRelsXml = new StringBuilder();
640-
var sheetRelsXml = new StringBuilder();
641640

642641
var sheetId = 0;
643642
foreach (var s in _sheets)
@@ -648,9 +647,9 @@ private void GenerateEndXml()
648647

649648
//TODO: support multiple drawing
650649
//TODO: ../drawings/drawing1.xml or /xl/drawings/drawing1.xml
651-
sheetRelsXml.Append($@"<Relationship Type=""http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"" Target=""../drawings/drawing1.xml"" Id=""drawing1"" />");
650+
var sheetRelsXml = $@"<Relationship Type=""http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"" Target=""../drawings/drawing1.xml"" Id=""drawing1"" />";
652651
CreateZipEntry($"xl/worksheets/_rels/sheet{s.SheetIdx}.xml.rels", "",
653-
_defaultSheetRelXml.Replace("{{format}}", sheetRelsXml.ToString()));
652+
_defaultSheetRelXml.Replace("{{format}}", sheetRelsXml));
654653
}
655654
CreateZipEntry(@"xl/workbook.xml", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml",
656655
_defaultWorkbookXml.Replace("{{sheets}}", workbookXml.ToString()));

tests/MiniExcelTests/MiniExcelIssueTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using static MiniExcelLibs.Tests.MiniExcelOpenXmlTests;
1919
using System.Collections;
2020
using MiniExcelLibs.Exceptions;
21+
using System.Text.RegularExpressions;
2122

2223
namespace MiniExcelLibs.Tests
2324
{
@@ -29,6 +30,24 @@ public MiniExcelIssueTests(ITestOutputHelper output)
2930
this.output = output;
3031
}
3132

33+
/// <summary>
34+
/// https://github.com/shps951023/MiniExcel/issues/325
35+
/// </summary>
36+
[Fact]
37+
public void TestIssue325()
38+
{
39+
var path = PathHelper.GetTempFilePath();
40+
var value = new Dictionary<string, object>()
41+
{
42+
{ "sheet1",new[]{ new { id = 1, date = DateTime.Parse("2022-01-01") } }},
43+
{ "sheet2",new[]{ new { id = 2, date = DateTime.Parse("2022-01-01") } }},
44+
};
45+
MiniExcel.SaveAs(path, value);
46+
var xml = Helpers.GetZipFileContent(path, "xl/worksheets/_rels/sheet2.xml.rels");
47+
var cnt = Regex.Matches(xml, "Id=\"drawing1\"").Count;
48+
Assert.True(cnt == 1);
49+
}
50+
3251
/// <summary>
3352
/// https://gitee.com/dotnetchina/MiniExcel/issues/I49RZH
3453
/// https://github.com/shps951023/MiniExcel/issues/305

0 commit comments

Comments
 (0)