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

Add disabled parameter to "Delete" tag and evaluate values before parsing #358

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove unused usings and move disabled to const
  • Loading branch information
vakssonya committed Jun 28, 2024
commit 60a5e91d08da19f8586079c424d2e3f7ff97fd01
57 changes: 31 additions & 26 deletions ClosedXML.Report/Options/DeleteTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace ClosedXML.Report.Options
{
public class DeleteTag : OptionTag
{
public const string DisabledParameter = "disabled";

public override void Execute(ProcessingContext context)
{
var deleteTags = List.GetAll<DeleteTag>()
Expand All @@ -24,33 +26,36 @@ public override void Execute(ProcessingContext context)

foreach (var tag in deleteTags)
{
if (!IsDisabled(tag))
if (IsDisabled(tag))
{
var xlCell = tag.Cell.GetXlCell(context.Range);
var cellAddr = xlCell.Address.ToStringRelative(false);
var ws = Range.Worksheet;
tag.Enabled = false;
continue;
}

var xlCell = tag.Cell.GetXlCell(context.Range);
var cellAddr = xlCell.Address.ToStringRelative(false);
var ws = Range.Worksheet;

// whole worksheet
if (cellAddr == "A1" || cellAddr == "A2")
{
ws.Workbook.Worksheets.Delete(ws.Name);
}
// whole column
else if (xlCell.Address.RowNumber == 1)
{
ws.Column(xlCell.Address.ColumnNumber).Delete();
}
// whole row
else if (xlCell.Address.ColumnNumber == 1)
{
ws.Row(xlCell.Address.RowNumber).Delete();
}
// range column
else if (IsSpecialRangeRow(xlCell))
{
var addrInRange = xlCell.Relative(Range.RangeAddress.FirstAddress);
context.Range.Column(addrInRange.ColumnNumber).Delete(XLShiftDeletedCells.ShiftCellsLeft);
}
// whole worksheet
if (cellAddr == "A1" || cellAddr == "A2")
{
ws.Workbook.Worksheets.Delete(ws.Name);
}
// whole column
else if (xlCell.Address.RowNumber == 1)
{
ws.Column(xlCell.Address.ColumnNumber).Delete();
}
// whole row
else if (xlCell.Address.ColumnNumber == 1)
{
ws.Row(xlCell.Address.RowNumber).Delete();
}
// range column
else if (IsSpecialRangeRow(xlCell))
{
var addrInRange = xlCell.Relative(Range.RangeAddress.FirstAddress);
context.Range.Column(addrInRange.ColumnNumber).Delete(XLShiftDeletedCells.ShiftCellsLeft);
}

tag.Enabled = false;
Expand All @@ -59,7 +64,7 @@ public override void Execute(ProcessingContext context)

private bool IsDisabled(DeleteTag tag)
{
return tag.Parameters.ContainsKey("disabled") && tag.Parameters["disabled"].AsBool();
return tag.Parameters.ContainsKey(DisabledParameter) && tag.Parameters[DisabledParameter].AsBool();
}
}
}
2 changes: 0 additions & 2 deletions tests/ClosedXML.Report.Tests/ReportOptionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Globalization;
using System.Linq;
using System.Threading;
using ClosedXML.Excel;
using ClosedXML.Report.Tests.TestModels;
using FluentAssertions;
Expand Down
Loading