Skip to content

Commit

Permalink
v2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mustaddon committed Sep 27, 2022
1 parent 7a6f8b9 commit 8bd9170
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
11 changes: 8 additions & 3 deletions ArrayToExcel/ArrayToExcel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,27 @@ static IEnumerable<Row> GetRows(IEnumerable items, List<ColumnSchema> columns)
foreach (var item in items)
{
var row = new Row() { RowIndex = i++ };
var cells = columns.Select((x, i) => GetCell(headerCells[i].CellReference, x.Value?.Invoke(item))).ToArray();
var cells = columns.Select((x, i) => GetCell(row.RowIndex, headerCells[i].CellReference, x.Value?.Invoke(item))).ToArray();
row.Append(cells);
yield return row;
}
}

static Cell GetCell(string? reference, object? value)
static Cell GetCell(uint rowIndex, string? cellReference, object? value)
{
var cell = new Cell { CellReference = reference };
var cell = new Cell { CellReference = cellReference };

if (value is string text)
{
cell.InlineString = GetInlineString(text);
cell.DataType = CellValues.InlineString;
cell.StyleIndex = 4;
}
else if (value is Formula formula)
{
cell.CellFormula = new CellFormula(formula.RowText(rowIndex));
cell.StyleIndex = 4;
}
else if (value is Hyperlink hyperlink)
{
cell.CellFormula = new CellFormula(hyperlink.ToString());
Expand Down
6 changes: 3 additions & 3 deletions ArrayToExcel/ArrayToExcel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<Nullable>enable</Nullable>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\ArrayToExcel.snk</AssemblyOriginatorKeyFile>
<AssemblyVersion>2.1.0</AssemblyVersion>
<FileVersion>2.1.0</FileVersion>
<Version>2.1.0</Version>
<AssemblyVersion>2.2.0</AssemblyVersion>
<FileVersion>2.2.0</FileVersion>
<Version>2.2.0</Version>
<Company></Company>
<Authors>Leonid Salavatov</Authors>
<Copyright>Leonid Salavatov 2022</Copyright>
Expand Down
17 changes: 17 additions & 0 deletions ArrayToExcel/Formula.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace ArrayToExcel
{
public class Formula
{
public Formula(string text) : this(row => text) { }

public Formula(Func<uint, string> rowText)
{
RowText = rowText;
}

internal Func<uint, string> RowText { get; }

}
}
1 change: 1 addition & 0 deletions Examples/Example.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ static void TestTypes()
DateTimeOffset = DateTimeOffset.Now.AddDays(-x),
Uri = new Uri($"https://www.google.com/search?q={x}"),
Hyperlink = new Hyperlink($"https://www.google.com/search?q={x}", $"link_{x}"),
Formula = new Formula(r => $"G{r}+H{r}"),
});

using var excel = items.ToExcelStream();
Expand Down

0 comments on commit 8bd9170

Please sign in to comment.