-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
102 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using DocumentFormat.OpenXml.Spreadsheet; | ||
using System; | ||
|
||
namespace ArrayToExcel; | ||
|
||
public class CellDate : ICellValue | ||
{ | ||
public CellDate(DateTime? dateTime, bool dateOnly = false) | ||
{ | ||
_value = dateTime?.ToString(_dateTimeFormat); | ||
_dateOnly = dateOnly; | ||
} | ||
|
||
public CellDate(DateTimeOffset? dateTime, bool dateOnly = false) | ||
{ | ||
_value = dateTime?.ToString(_dateTimeFormat); | ||
_dateOnly = dateOnly; | ||
} | ||
|
||
#if NET6_0_OR_GREATER | ||
public CellDate(DateOnly? date) | ||
{ | ||
_value = date?.ToString(_dateFormat); | ||
_dateOnly = true; | ||
} | ||
|
||
static readonly string _dateFormat = "o"; | ||
#endif | ||
|
||
static readonly string _dateTimeFormat = "s"; | ||
readonly string? _value; | ||
readonly bool _dateOnly; | ||
|
||
public virtual void Apply(Cell cell, uint row) | ||
{ | ||
|
||
cell.CellValue = new(_value ?? string.Empty); | ||
cell.DataType = CellValues.Date; | ||
cell.StyleIndex = _dateOnly ? Styles.Date : Styles.DateTime; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace ArrayToExcel; | ||
|
||
public static class Styles | ||
{ | ||
public static readonly uint Header = 1; | ||
public static readonly uint Default = 2; | ||
public static readonly uint WrapText = 3; | ||
public static readonly uint Date = 4; | ||
public static readonly uint DateTime = 5; | ||
public static readonly uint Hyperlink = 6; | ||
public static readonly uint Percentage = 7; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters