Skip to content
This repository was archived by the owner on Nov 14, 2022. It is now read-only.

Commit 4e83663

Browse files
authored
Merge pull request #30 from stesee/develop
Adapting to new MS Excel behavior causing Exceptions with Notes on loading Pivot Table custom captions GrandTotalCaption and DataCaption save+load
2 parents abdeffc + 240789f commit 4e83663

File tree

14 files changed

+171
-57
lines changed

14 files changed

+171
-57
lines changed

.github/workflows/dotnet.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v3
1818
- name: Setup .NET
19-
uses: actions/setup-dotnet@v1
19+
uses: actions/setup-dotnet@v2
2020
with:
2121
dotnet-version: 6.0.x
2222
- name: Restore dependencies
@@ -41,17 +41,21 @@ jobs:
4141
- name: Build
4242
run: dotnet build --configuration Release --no-restore
4343
- name: NugetPush
44+
env:
45+
NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TOKEN }}
46+
if: env.NUGET_TOKEN_EXISTS != ''
4447
run: |
48+
ls ./ClosedXML/bin/Release
4549
dotnet nuget push .\ClosedXML\bin\Release\*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TOKEN}} --source https://api.nuget.org/v3/index.json
46-
- uses: "marvinpinto/action-automatic-releases@latest"
50+
- name: GithubReleasesPush
51+
uses: "marvinpinto/action-automatic-releases@latest"
4752
with:
4853
repo_token: "${{ secrets.GITHUB_TOKEN }}"
4954
automatic_release_tag: ${{ env.CURRENT_VERSION }}
5055
prerelease: false
5156
title: "Release Build ${{ env.CURRENT_VERSION }}"
5257
files: |
5358
./ClosedXML/bin/Release/*.nupkg
54-
./ClosedXML/bin/Release/*.snupkg
5559
5660
deployTest:
5761
if: github.ref != 'refs/heads/main'
@@ -68,15 +72,18 @@ jobs:
6872
- name: Build
6973
run: dotnet build --configuration Release --no-restore
7074
- name: NugetPush
75+
env:
76+
NUGET_TOKEN_EXISTS: ${{ secrets.NUGET_TEST_TOKEN }}
77+
if: env.NUGET_TOKEN_EXISTS != ''
7178
run: |
7279
ls ./ClosedXML/bin/Release
7380
dotnet nuget push .\ClosedXML\bin\Release\*.nupkg --skip-duplicate --api-key ${{secrets.NUGET_TEST_TOKEN}} --source https://apiint.nugettest.org/v3/index.json
74-
- uses: "marvinpinto/action-automatic-releases@latest"
81+
- name: GithubReleasesPush
82+
uses: "marvinpinto/action-automatic-releases@latest"
7583
with:
7684
repo_token: "${{ secrets.GITHUB_TOKEN }}"
7785
automatic_release_tag: "latest-prerelease"
7886
prerelease: true
7987
title: "Prerelease Build ${{ env.CURRENT_VERSION }}"
8088
files: |
8189
./ClosedXML/bin/Release/*.nupkg
82-
./ClosedXML/bin/Release/*.snupkg

ClosedXML.Tests/Excel/Loading/LoadingTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ public void CanLoadAndManipulateFileWithEmptyTable()
7676
}
7777
}
7878

79+
[Test]
80+
public void CanLoadAndSaveCommentAsNoteWithNoTextBox()
81+
{
82+
using (var stream = TestHelper.GetStreamFromResource(TestHelper.GetResourcePath(@"TryToLoad\CommentAsNoteWithNoTextBox.xlsx")))
83+
using (var wb = new XLWorkbook(stream))
84+
{
85+
var ws = wb.Worksheets.First();
86+
Assert.AreEqual("Author:\r\nbla", ws.Cell("A3").GetComment().Text);
87+
88+
using (var ms = new MemoryStream())
89+
{
90+
wb.SaveAs(ms, true);
91+
}
92+
}
93+
}
94+
7995
[Test]
8096
public void CanLoadDate1904SystemCorrectly()
8197
{
@@ -393,6 +409,23 @@ public void CanLoadWorksheetStyle()
393409
}
394410
}
395411

412+
[Test]
413+
public void CanLoadNullText()
414+
{
415+
using (var stream = TestHelper.GetStreamFromResource(TestHelper.GetResourcePath(@"TryToLoad\TextNull.xlsx")))
416+
using (var wb = new XLWorkbook(stream))
417+
{
418+
var ws = wb.Worksheet(1);
419+
Assert.Multiple(() =>
420+
{
421+
Assert.That(ws.Cell("C9").Value, Is.EqualTo(""));
422+
Assert.That(ws.Cell("A1").Value, Is.EqualTo("姓名"));
423+
Assert.That(ws.Cell("B1").Value, Is.EqualTo("年龄"));
424+
Assert.That(ws.Cell("C11").Value, Is.EqualTo("服务"));
425+
});
426+
}
427+
}
428+
396429
[Test]
397430
public void CanCorrectLoadWorkbookCellWithStringDataType()
398431
{

ClosedXML.Tests/Excel/PivotTables/XLPivotTableTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public void PivotTableOptionsSaveTest()
111111
pt.ShowColumnStripes = true;
112112
pt.Theme = XLPivotTableTheme.PivotStyleDark13;
113113

114+
pt.DataCaption = "Test Caption Values";
115+
pt.GrandTotalCaption = "Test Grand Total Caption";
116+
114117
using (var ms = new MemoryStream())
115118
{
116119
wb.SaveAs(ms, true);
@@ -160,6 +163,40 @@ public void PivotTableOptionsSaveTest()
160163
Assert.AreEqual(false, ptassert.ShowColumnHeaders, "ShowColumnHeaders save failure");
161164
Assert.AreEqual(true, ptassert.ShowRowStripes, "ShowRowStripes save failure");
162165
Assert.AreEqual(true, ptassert.ShowColumnStripes, "ShowColumnStripes save failure");
166+
Assert.AreEqual("Test Caption Values", ptassert.DataCaption, "DataCaption save failure");
167+
Assert.AreEqual("Test Grand Total Caption", ptassert.GrandTotalCaption, "GrandTotalCaption save failure");
168+
}
169+
}
170+
}
171+
}
172+
173+
[Test]
174+
public void PivotTableOptionsSaveTest_CaptionsNotSet()
175+
{
176+
using (var stream = TestHelper.GetStreamFromResource(TestHelper.GetResourcePath(@"Examples\PivotTables\PivotTables.xlsx")))
177+
using (var wb = new XLWorkbook(stream))
178+
{
179+
var ws = wb.Worksheet("PastrySalesData");
180+
var table = ws.Table("PastrySalesData");
181+
var ptSheet = wb.Worksheets.Add("BlankPivotTable");
182+
var pt = ptSheet.PivotTables.Add("pvtOptionsTest", ptSheet.Cell(1, 1), table);
183+
184+
pt.DataCaption = null;
185+
pt.GrandTotalCaption = null;
186+
187+
using (var ms = new MemoryStream())
188+
{
189+
wb.SaveAs(ms, true);
190+
191+
ms.Position = 0;
192+
193+
using (var wbassert = new XLWorkbook(ms))
194+
{
195+
var wsassert = wbassert.Worksheet("BlankPivotTable");
196+
var ptassert = wsassert.PivotTable("pvtOptionsTest");
197+
198+
Assert.AreEqual("Values", ptassert.DataCaption, "DataCaption save failure");
199+
Assert.AreEqual(null, ptassert.GrandTotalCaption, "GrandTotalCaption save failure");
163200
}
164201
}
165202
}

ClosedXML.Tests/Extensions/ReflectionExtensionTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ static TestClass()
1515
}
1616

1717
public static int StaticProperty { get; set; }
18+
#pragma warning disable 0649
1819
public static int StaticField;
20+
#pragma warning restore 0649
21+
22+
#pragma warning disable 0067
1923

2024
public static event EventHandler<EventArgs> StaticEvent;
2125

26+
#pragma warning restore 0067
27+
2228
public static void StaticMethod()
2329
{
2430
}
@@ -30,10 +36,16 @@ public TestClass()
3036
}
3137

3238
public int InstanceProperty { get; set; }
39+
#pragma warning disable 0649
3340
public int InstanceField;
41+
#pragma warning restore 0649
42+
43+
#pragma warning disable 0067
3444

3545
public event EventHandler<EventArgs> InstanceEvent;
3646

47+
#pragma warning restore 0067
48+
3749
public void InstanceMethod()
3850
{
3951
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
9.56 KB
Binary file not shown.

ClosedXML.Tests/Utils/PivotTableComparer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public bool Equals(XLPivotTable x, XLPivotTable y)
4141

4242
&& StringComparer.CurrentCulture.Equals(x.Title, y.Title)
4343
&& StringComparer.CurrentCulture.Equals(x.Description, y.Description)
44+
&& StringComparer.CurrentCulture.Equals(x.GrandTotalCaption, y.GrandTotalCaption)
45+
&& StringComparer.CurrentCulture.Equals(x.DataCaption, y.DataCaption)
4446
&& StringComparer.CurrentCulture.Equals(x.ColumnHeaderCaption, y.ColumnHeaderCaption)
4547
&& StringComparer.CurrentCulture.Equals(x.RowHeaderCaption, y.RowHeaderCaption)
4648
&& x.MergeAndCenterWithLabels.Equals(y.MergeAndCenterWithLabels)

0 commit comments

Comments
 (0)