Skip to content

Commit 6bf6589

Browse files
committed
Support for ClosedXml 0.94
1 parent 474a4f1 commit 6bf6589

File tree

8 files changed

+36
-27
lines changed

8 files changed

+36
-27
lines changed

ExcelReportGenerator.Tests/CustomAsserts/ExcelAssert.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public static void AreWorksheetsContentEquals(IXLWorksheet expected, IXLWorkshee
1313
return;
1414
}
1515

16-
Assert.AreEqual(expected.CellsUsed(true).Count(), actual.CellsUsed(true).Count(), "Cells used count failed");
16+
Assert.AreEqual(expected.CellsUsed(XLCellsUsedOptions.All).Count(), actual.CellsUsed(XLCellsUsedOptions.All).Count(), "Cells used count failed");
1717

18-
IXLCell expectedFirstCellUsed = expected.FirstCellUsed(true);
19-
IXLCell actualFirstCellUsed = actual.FirstCellUsed(true);
18+
IXLCell expectedFirstCellUsed = expected.FirstCellUsed(XLCellsUsedOptions.All);
19+
IXLCell actualFirstCellUsed = actual.FirstCellUsed(XLCellsUsedOptions.All);
2020
Assert.AreEqual(expectedFirstCellUsed.Address, actualFirstCellUsed.Address, "First cell used failed");
21-
IXLCell expectedLastCellUsed = expected.LastCellUsed(true);
22-
IXLCell actualLastCellUsed = actual.LastCellUsed(true);
21+
IXLCell expectedLastCellUsed = expected.LastCellUsed(XLCellsUsedOptions.All);
22+
IXLCell actualLastCellUsed = actual.LastCellUsed(XLCellsUsedOptions.All);
2323
Assert.AreEqual(expectedLastCellUsed.Address, actualLastCellUsed.Address, "Last cell used failed");
2424

2525
IXLRange range = expected.Range(expectedFirstCellUsed, expectedLastCellUsed);

ExcelReportGenerator.Tests/Excel/ExcelHelperTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -993,8 +993,8 @@ public void TestCloneRange()
993993

994994
Assert.AreEqual(range, ExcelHelper.CloneRange(range));
995995

996-
// Since ClosedXml 0.93.0 this test does not pass
997-
Assert.AreNotSame(range, ExcelHelper.CloneRange(range));
996+
//// Since ClosedXml 0.93.0 this test does not pass
997+
//Assert.AreNotSame(range, ExcelHelper.CloneRange(range));
998998

999999
Assert.IsNull(ExcelHelper.CloneRange(null));
10001000
}

ExcelReportGenerator.Tests/Extensions/XLRangeBaseExtensionsTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public void TestCellsUsedWithoutFormulas()
2323
ws.Cell(25, 30).FormulaA1 = "=A1+B2";
2424

2525
Assert.AreEqual(5, ws.CellsUsed().Count());
26-
Assert.AreEqual(6, ws.CellsUsed(true).Count());
26+
Assert.AreEqual(6, ws.CellsUsed(XLCellsUsedOptions.All).Count());
2727
Assert.AreEqual(2, ws.CellsUsedWithoutFormulas().Count());
28-
Assert.AreEqual(3, ws.CellsUsedWithoutFormulas(true).Count());
28+
Assert.AreEqual(3, ws.CellsUsedWithoutFormulas(XLCellsUsedOptions.All).Count());
2929
Assert.AreEqual(2, ws.CellsUsed(c => c.Active || c.Style.Border.TopBorder == XLBorderStyleValues.Thin).Count());
3030
Assert.AreEqual(1, ws.CellsUsedWithoutFormulas(c => c.Active || c.Style.Border.TopBorder == XLBorderStyleValues.Thin).Count());
31-
Assert.AreEqual(3, ws.CellsUsed(true, c => c.Active || c.Style.Border.TopBorder == XLBorderStyleValues.Thin).Count());
32-
Assert.AreEqual(2, ws.CellsUsedWithoutFormulas(true, c => c.Active || c.Style.Border.TopBorder == XLBorderStyleValues.Thin).Count());
31+
Assert.AreEqual(3, ws.CellsUsed(XLCellsUsedOptions.All, c => c.Active || c.Style.Border.TopBorder == XLBorderStyleValues.Thin).Count());
32+
Assert.AreEqual(2, ws.CellsUsedWithoutFormulas(XLCellsUsedOptions.All, c => c.Active || c.Style.Border.TopBorder == XLBorderStyleValues.Thin).Count());
3333
}
3434

3535
[Test]

ExcelReportGenerator.Tests/Rendering/Panels/ExcelPanels/PanelRenderTests/DataSourceDynamicPanelRenderTests/DataSourceDynamicPanelDataSetRenderTest.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
using System.Linq;
2-
using ClosedXML.Excel;
1+
using ClosedXML.Excel;
32
using ExcelReportGenerator.Enums;
43
using ExcelReportGenerator.Rendering.Panels.ExcelPanels;
54
using ExcelReportGenerator.Tests.CustomAsserts;
65
using NUnit.Framework;
6+
using System;
7+
using System.IO;
8+
using System.Linq;
79

810
namespace ExcelReportGenerator.Tests.Rendering.Panels.ExcelPanels.PanelRenderTests.DataSourceDynamicPanelRenderTests
911
{
10-
1112
public class DataSourceDynamicPanelDataSetRenderTest
1213
{
1314
[Test]
@@ -45,14 +46,15 @@ public void TestRenderDataSetWithEvents()
4546

4647
Assert.AreEqual(ws.Range(2, 2, 7, 8), panel.ResultRange);
4748

48-
// Bug of ClosedXml - invalid determine of FirstCellUsed and LastCellUsed if merged ranges exist
49-
ws.Cell(1, 1).Value = "Stub";
50-
ws.Range(1, 1, 1, 1).Merge();
51-
ws.Cell(8, 9).Value = "Stub";
52-
ws.Range(8, 9, 8, 9).Merge();
49+
// The test doesn't pass if we compare the expected workbook with the in-memory workbook (since ClosedXml 0.94.0)
50+
string actualWorkbookName = $"{Guid.NewGuid()}.xlsx";
51+
report.Workbook.SaveAs(actualWorkbookName);
52+
var actualWorkbook = new XLWorkbook(actualWorkbookName);
5353

5454
ExcelAssert.AreWorkbooksContentEquals(TestHelper.GetExpectedWorkbook(nameof(DataSourceDynamicPanelDataSetRenderTest),
55-
nameof(TestRenderDataSetWithEvents)), ws.Workbook);
55+
nameof(TestRenderDataSetWithEvents)), actualWorkbook);
56+
57+
File.Delete(actualWorkbookName);
5658

5759
//report.Workbook.SaveAs("test.xlsx");
5860
}
@@ -90,8 +92,15 @@ public void TestRenderDataSetWithEvents_HorizontalPanel()
9092

9193
Assert.AreEqual(ws.Range(2, 2, 8, 6), panel.ResultRange);
9294

95+
// The test doesn't pass if we compare the expected workbook with the in-memory workbook (since ClosedXml 0.94.0)
96+
string actualWorkbookName = $"{Guid.NewGuid()}.xlsx";
97+
report.Workbook.SaveAs(actualWorkbookName);
98+
var actualWorkbook = new XLWorkbook(actualWorkbookName);
99+
93100
ExcelAssert.AreWorkbooksContentEquals(TestHelper.GetExpectedWorkbook(nameof(DataSourceDynamicPanelDataSetRenderTest),
94-
nameof(TestRenderDataSetWithEvents_HorizontalPanel)), ws.Workbook);
101+
nameof(TestRenderDataSetWithEvents_HorizontalPanel)), actualWorkbook);
102+
103+
File.Delete(actualWorkbookName);
95104

96105
//report.Workbook.SaveAs("test.xlsx");
97106
}

ExcelReportGenerator/Excel/ExcelHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public static bool IsRangeInvalid(IXLRange range)
280280
range.FirstColumn().ColumnNumber();
281281
range.LastColumn().ColumnNumber();
282282
}
283-
catch (IndexOutOfRangeException)
283+
catch (ArgumentOutOfRangeException)
284284
{
285285
return true;
286286
}

ExcelReportGenerator/ExcelReportGenerator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
<!-- Common NuGet package refs that affect all projects -->
2424
<ItemGroup>
25-
<PackageReference Include="ClosedXML" Version="0.93.1" />
25+
<PackageReference Include="ClosedXML" Version="0.94.0" />
2626
</ItemGroup>
2727

2828
<!-- .NET Standard 2.0 -->

ExcelReportGenerator/Extensions/XLRangeBaseExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ public static IXLCells CellsUsedWithoutFormulas(this IXLRangeBase range, Func<IX
1515
return range.CellsUsed(c => predicate(c) && !c.HasFormula);
1616
}
1717

18-
public static IXLCells CellsUsedWithoutFormulas(this IXLRangeBase range, bool includeFormats)
18+
public static IXLCells CellsUsedWithoutFormulas(this IXLRangeBase range, XLCellsUsedOptions options)
1919
{
20-
return range.CellsUsed(includeFormats, c => !c.HasFormula);
20+
return range.CellsUsed(options, c => !c.HasFormula);
2121
}
2222

23-
public static IXLCells CellsUsedWithoutFormulas(this IXLRangeBase range, bool includeFormats, Func<IXLCell, bool> predicate)
23+
public static IXLCells CellsUsedWithoutFormulas(this IXLRangeBase range, XLCellsUsedOptions options, Func<IXLCell, bool> predicate)
2424
{
25-
return range.CellsUsed(includeFormats, c => predicate(c) && !c.HasFormula);
25+
return range.CellsUsed(options, c => predicate(c) && !c.HasFormula);
2626
}
2727

2828
public static IXLCells CellsWithoutFormulas(this IXLRangeBase range)

0 commit comments

Comments
 (0)