Skip to content

Commit

Permalink
v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mustaddon committed Sep 12, 2022
1 parent d8021c8 commit 7a6f8b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
34 changes: 23 additions & 11 deletions ArrayToExcel/ArrayToExcel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void AddStyles(WorkbookPart workbookPart)
stylesPart.Stylesheet.CellFormats.AppendChild(new CellFormat { FormatId = 0, FontId = 2 }).AppendChild(new Alignment() { Vertical = VerticalAlignmentValues.Top });
// multiline style
stylesPart.Stylesheet.CellFormats.AppendChild(new CellFormat()).AppendChild(new Alignment() { Vertical = VerticalAlignmentValues.Top, WrapText = true });

stylesPart.Stylesheet.CellFormats.Count = (uint)stylesPart.Stylesheet.CellFormats.ChildElements.Count;

stylesPart.Stylesheet.Save();
Expand Down Expand Up @@ -173,26 +173,30 @@ static IEnumerable<Row> GetRows(IEnumerable items, List<ColumnSchema> columns)

static Cell GetCell(string? reference, object? value)
{
var dataType = GetCellType(value);
var cell = new Cell { CellReference = reference };

var cell = new Cell
if (value is string text)
{
CellReference = reference,
CellValue = GetCellValue(value),
DataType = dataType,
StyleIndex = dataType == CellValues.Date ? 2 : 4u,
};

if (value is Hyperlink hyperlink)
cell.InlineString = GetInlineString(text);
cell.DataType = CellValues.InlineString;
cell.StyleIndex = 4;
}
else if (value is Hyperlink hyperlink)
{
cell.CellFormula = new CellFormula(hyperlink.ToString());
cell.StyleIndex = 3;
}
}
else if (value is Uri uri)
{
cell.CellFormula = new CellFormula(new Hyperlink(uri).ToString());
cell.StyleIndex = 3;
}
else
{
cell.CellValue = GetCellValue(value);
cell.DataType = GetCellType(value);
cell.StyleIndex = cell.DataType == CellValues.Date ? 2 : 4u;
}

return cell;
}
Expand Down Expand Up @@ -224,6 +228,14 @@ static CellValue GetCellValue(object? value)
return new(_invalidXmlChars.Replace(value.ToString(), string.Empty));
}

static InlineString GetInlineString(string value)
{
return new InlineString(new Text(_invalidXmlChars.Replace(value, string.Empty))
{
Space = SpaceProcessingModeValues.Preserve
});
}

static CellValues GetCellType(object? value)
{
var type = value?.GetType() ?? typeof(object);
Expand Down
8 changes: 4 additions & 4 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.0.7</AssemblyVersion>
<FileVersion>2.0.7</FileVersion>
<Version>2.0.7</Version>
<AssemblyVersion>2.1.0</AssemblyVersion>
<FileVersion>2.1.0</FileVersion>
<Version>2.1.0</Version>
<Company></Company>
<Authors>Leonid Salavatov</Authors>
<Copyright>Leonid Salavatov 2022</Copyright>
Expand All @@ -28,7 +28,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.15.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.18.0" />
</ItemGroup>

</Project>

0 comments on commit 7a6f8b9

Please sign in to comment.