Skip to content

Commit

Permalink
Add height and heightrange tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Malov Gleb committed Jul 3, 2024
1 parent dbdd97b commit 1e8a468
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
18 changes: 18 additions & 0 deletions ClosedXML.Report/Options/HeightRangeTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Linq;
using ClosedXML.Report.Utils;

namespace ClosedXML.Report.Options
{
public class HeightRangeTag : RangeOptionTag
{
public int Height => Parameters.Any() ? Parameters.First().Key.AsInt() : 0;

public override void Execute(ProcessingContext context)
{
var firstRow = context.Range.FirstRowUsed();
var lastRow = context.Range.LastRowUsed();

Range.Worksheet.Rows(firstRow.WorksheetRow().RowNumber(), lastRow.WorksheetRow().RowNumber()).Height = Height;
}
}
}
17 changes: 17 additions & 0 deletions ClosedXML.Report/Options/HeightTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Linq;
using ClosedXML.Report.Utils;

namespace ClosedXML.Report.Options;

public class HeightTag : OptionTag
{
public int Height => Parameters.Any() ? Parameters.First().Key.AsInt() : 0;

public override void Execute(ProcessingContext context)
{
var xlCell = Cell.GetXlCell(context.Range);
var cellRow = xlCell.WorksheetRow().RowNumber();

Range.Worksheet.Rows(cellRow, cellRow).Height = Height;
}
}
17 changes: 12 additions & 5 deletions ClosedXML.Report/RangeTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ private static IEnumerable<IXLNamedRange> GetInnerRanges(IXLRange prng)
public IReportBuffer Generate(object[] items)
{
_evaluator.AddVariable("items", items);

foreach (var v in _globalVariables)
{
_evaluator.AddVariable("@" + v.Key, v.Value);
}
_rangeTags.Reset();

if (IsHorizontal)
{
Expand All @@ -160,6 +160,7 @@ public IReportBuffer Generate(object[] items)
{
VerticalTable(items, _evaluator);
}

return _buff;
}

Expand Down Expand Up @@ -482,10 +483,16 @@ where TagExtensions.HasTag(value)
tags = _tagsEvaluator.Parse(cell.GetString(), range, cell, out newValue);
cell.Value = newValue;
}
if (cell.Row > 1 && cell.Row == _rowCnt)
_rangeTags.AddRange(tags);
else
_tags.AddRange(tags);

foreach (var optionTag in tags)
{
if (cell.Row > 1 && cell.Row == _rowCnt)
_rangeTags.Add(optionTag);
else if (optionTag is RangeOptionTag)
_rangeTags.Add(optionTag);
else
_tags.Add(optionTag);
}
}

_rangeOption = _rangeTags.GetAll<RangeOptionTag>().Union(_tags.GetAll<RangeOptionTag>()).FirstOrDefault();
Expand Down
2 changes: 2 additions & 0 deletions ClosedXML.Report/XLTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ static XLTemplate()
TagsRegister.Add<HiddenTag>("Hide", 0);
TagsRegister.Add<PageOptionsTag>("PageOptions", 0);
TagsRegister.Add<ProtectedTag>("Protected", 0);
TagsRegister.Add<HeightTag>("Height", 0);
TagsRegister.Add<HeightRangeTag>("HeightRange", 0);
}

public XLTemplate(string fileName) : this(new XLWorkbook(fileName))
Expand Down

0 comments on commit 1e8a468

Please sign in to comment.