Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clear table placeholders when data is empty #344

Merged
merged 6 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ClosedXML.Report/ClosedXML.Report.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
smakaiberriesandco marked this conversation as resolved.
Show resolved Hide resolved
<LangVersion>10</LangVersion>
<AssemblyName>ClosedXML.Report</AssemblyName>
<PackageId>ClosedXML.Report</PackageId>
Expand Down Expand Up @@ -37,7 +37,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.102.0" />
<PackageReference Include="ClosedXML" Version="0.102.2" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="morelinq" Version="3.4.1" />
<PackageReference Include="System.Linq.Dynamic.Core" Version="1.3.0" />
Expand Down
4 changes: 2 additions & 2 deletions ClosedXML.Report/RangeInterpreter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ string EvalString(string str)
{
if (growedRange.IsOptionsRowEmpty())
{
growedRange.Delete(XLShiftDeletedCells.ShiftCellsUp);
growedRange.Clear();
}
else
{
var rangeWithoutOptionsRow = growedRange.Worksheet
.Range(growedRange.FirstCell(), growedRange.LastCell().CellAbove());
rangeWithoutOptionsRow.Delete(XLShiftDeletedCells.ShiftCellsUp);
rangeWithoutOptionsRow.Clear();
}
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ClosedXML.Report.Tests/ClosedXML.Report.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>ClosedXML.Report.snk</AssemblyOriginatorKeyFile>
<GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 11 additions & 1 deletion tests/ClosedXML.Report.Tests/RangeInterpreterTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ClosedXML.Excel;
using FluentAssertions;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -108,7 +109,7 @@ public void ShouldNotThrowExceptionIfAccessSomeChildrenNullProp()
public void ShouldDestroyEmptyTable()
smakaiberriesandco marked this conversation as resolved.
Show resolved Hide resolved
{
//See #251
var template = CreateOrderTemplate();
var template = CreateEmptyTemplate();
var ws = template.Workbook.Worksheets.First();

ws.Cell("B4").SetValue("This list is empty");
Expand All @@ -135,6 +136,15 @@ public void ShouldDestroyEmptyTable()
ws.Cell("B6").GetString().Should().Be("It works");
}

private XLTemplate CreateEmptyTemplate()
{
var wbTemplate = new XLWorkbook();

wbTemplate.AddWorksheet();

return new XLTemplate(wbTemplate);
}

private XLTemplate CreateOrderTemplate()
{
var wbTemplate = new XLWorkbook();
Expand Down
Loading