Skip to content

Commit dbc8ac7

Browse files
authored
Merge pull request #67 from PandaTechAM/development
In case of wrong dates xlsx export will not throw an excep…
2 parents 827f5f7 + 6cb0e46 commit dbc8ac7

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

src/FileExporter/Exporters/XlsxExporter.cs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.IO;
45
using System.Linq;
56
using System.Threading;
@@ -308,23 +309,40 @@ private static Cell CreateCell(object value)
308309
{
309310
return value switch
310311
{
311-
string s => new Cell(s),
312-
bool b => new Cell(b),
313-
int i => new Cell(i),
314-
long l => new Cell(l),
315-
short sh => new Cell(sh),
316-
byte b8 => new Cell(b8),
317-
uint ui => new Cell((double)ui),
318-
ulong ul => new Cell((double)ul),
319-
float f => new Cell((double)f),
320-
double d => new Cell(d),
321-
decimal m => new Cell((double)m),
322-
DateTime dt => new Cell(dt),
323-
DateOnly d => new Cell(d.ToDateTime(TimeOnly.MinValue)),
324-
TimeOnly t => new Cell(DateTime.Today.Add(t.ToTimeSpan())),
312+
string s => new Cell(s),
313+
bool b => new Cell(b),
314+
int i => new Cell(i),
315+
long l => new Cell(l),
316+
short sh => new Cell(sh),
317+
byte b8 => new Cell(b8),
318+
uint ui => new Cell((double)ui),
319+
ulong ul => new Cell((double)ul),
320+
float f => new Cell((double)f),
321+
double d => new Cell(d),
322+
decimal m => new Cell((double)m),
323+
324+
DateTime dt => CreateDateCell(dt),
325+
DateOnly d => CreateDateCell(d.ToDateTime(TimeOnly.MinValue)),
326+
TimeOnly t => CreateDateCell(DateTime.Today.Add(t.ToTimeSpan())),
327+
325328
_ => new Cell(value.ToString() ?? string.Empty)
326329
};
327330
}
331+
332+
private static Cell CreateDateCell(DateTime dt)
333+
{
334+
try
335+
{
336+
return new Cell(dt);
337+
}
338+
catch (Exception)
339+
{
340+
// Fallback: keep the value, but as text to avoid breaking the whole export.
341+
// ISO 8601 is unambiguous and sorts nicely in Excel.
342+
var asText = dt.ToString("O", CultureInfo.InvariantCulture);
343+
return new Cell(asText);
344+
}
345+
}
328346

329347
private static async Task<byte[]> CreateMultiSheetXlsxFileAsync<T>(IList<T> list,
330348
List<ExportColumn> columns,

src/FileExporter/FileExporter.csproj

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<PackageIcon>Logo.jpg</PackageIcon>
1313
<PackageReadmeFile>Readme.md</PackageReadmeFile>
1414

15-
<Version>5.0.0</Version>
15+
<Version>5.0.1</Version>
1616

1717
<Title>PandaTech File Exporter</Title>
1818

@@ -31,14 +31,7 @@
3131
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-file-exporter</RepositoryUrl>
3232

3333
<PackageReleaseNotes>
34-
v5 major redesign. Breaking changes from v4.
35-
- New rule system and naming engine
36-
- Multi-sheet XLSX support
37-
- Massive performance improvements
38-
- Async streaming (IAsyncEnumerable)
39-
- Removed PDF support
40-
- Updated enum format modes
41-
- Safer sanitization and file naming
34+
In case of wrong dates xlsx export will not throw an exception anymore but will export that row with string value instead.
4235
</PackageReleaseNotes>
4336
</PropertyGroup>
4437

0 commit comments

Comments
 (0)