Skip to content

Commit

Permalink
Merge pull request #12 from skbkontur/a.dobrynin/optimize-print
Browse files Browse the repository at this point in the history
optimize print
  • Loading branch information
aldobrynin authored Jan 19, 2023
2 parents b6557a8 + eda6685 commit 8c8d7fd
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
1 change: 1 addition & 0 deletions Benchmark/Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net472;net6.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@ public FakeCell(ICellPosition position)
CellPosition = position;
}

public string StringValue { get; set; }
public CellType CellType { get; set; }
public string StringValue { get; private set; }
public CellType CellType { get; private set; }

public void SetValue(string stringValue, CellType cellType)
{
StringValue = stringValue;
CellType = cellType;
}

public ICellPosition CellPosition { get; }

public void CopyStyle(ICell templateCell)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static FakeTable GenerateFromStringArray(string[][] template)
for (var x = 0; x < width; ++x)
{
var cell = table.InsertCell(new CellPosition(y + 1, x + 1));
cell.StringValue = template[y][x];
cell.SetValue(template[y][x], CellType.String);
}
}
return table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void FakeTableCellManipulationTest()
cell.Should().NotBeNull();

const string testValue = "Test Value";
cell.StringValue = testValue;
cell.SetValue(testValue);

cell = table.GetCell(position);

Expand Down Expand Up @@ -89,7 +89,7 @@ public void FakeTableCellSearchTest()
for (var i = 0; i < positions.Count(); ++i)
{
var cell = table.InsertCell(positions[i]);
cell.StringValue = stringValues[i];
cell.SetValue(stringValues[i]);
}

var cells = table.SearchCellByText("Test");
Expand Down Expand Up @@ -124,7 +124,7 @@ public void FakeTablePartExtractionTest()
for (var i = 0; i < positions.Count(); ++i)
{
var cell = table.InsertCell(positions[i]);
cell.StringValue = stringValues[i];
cell.SetValue(stringValues[i]);
}

var tablePart = table.GetTablePart(new Rectangle(new CellPosition(9, 9), new CellPosition(40, 20)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void StringValuePrintingTest()
{
var template = new FakeTable(1, 1);
var cell = template.InsertCell(new CellPosition(1, 1));
cell.StringValue = "Template:RootTemplate:A1:A1";
cell.SetValue("Template:RootTemplate:A1:A1");

var templateEngine = new TemplateEngine(template, logger);

Expand All @@ -48,7 +48,7 @@ public void SimpleTestWithArray()

var template = new FakeTable(1, 1);
var cell = template.InsertCell(new CellPosition(1, 1));
cell.StringValue = "Template:RootTemplate:A1:A1";
cell.SetValue("Template:RootTemplate:A1:A1");

var templateEngine = new TemplateEngine(template, logger);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace SkbKontur.Excel.TemplateEngine.ObjectPrinting.ExcelDocumentPrimitives
public interface ICell
{
void CopyStyle(ICell templateCell);
string StringValue { get; set; }
CellType CellType { set; }
string StringValue { get; }
void SetValue(string stringValue, CellType cellType = CellType.String);
ICellPosition CellPosition { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,22 @@ public ExcelCell(IExcelCell excelCell)
internalCell = excelCell;
}

public string StringValue { get => internalCell.GetStringValue(); set => internalCell.SetStringValue(value); }

public CellType CellType
{
set
{
if (value == CellType.String)
internalCell.SetStringValue(StringValue);
else
internalCell.SetNumericValue(StringValue);
}
}
public string StringValue => internalCell.GetStringValue();

public void CopyStyle(ICell templateCell)
{
var excelCell = ((ExcelCell)templateCell);
internalCell.SetStyle(excelCell.internalCell.GetStyle());
}

public void SetValue(string stringValue, CellType cellType)
{
if (cellType == CellType.String)
internalCell.SetStringValue(stringValue);
else
internalCell.SetNumericValue(stringValue);
}

public ICellPosition CellPosition => new CellPosition(internalCell.GetCellIndex());

private readonly IExcelCell internalCell;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ public ITableBuilder CopyCommentsFrom([NotNull] ITable template)
private ITableBuilder RenderAtomicValue(string value, CellType cellType)
{
var cell = target.GetCell(navigator.CurrentState.Cursor) ?? target.InsertCell(navigator.CurrentState.Cursor);
cell.StringValue = value;
cell.CellType = cellType;
cell.SetValue(value, cellType);
return this;
}

Expand Down

0 comments on commit 8c8d7fd

Please sign in to comment.