Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,13 @@ protected override async Task GenerateCellXfAsync()
await NewWriter.WriteEndElementAsync().ConfigureAwait(false);

/*
* <x:xf numFmtId="21" fontId="0" fillId="0" borderId="1" xfId="0" applyNumberFormat="1" applyFill="1" applyBorder="1" applyAlignment="1" applyProtection="1">
* <x:xf numFmtId="46" fontId="0" fillId="0" borderId="1" xfId="0" applyNumberFormat="1" applyFill="1" applyBorder="1" applyAlignment="1" applyProtection="1">
* <x:alignment horizontal="general" vertical="bottom" textRotation="0" wrapText="0" indent="0" relativeIndent="0" justifyLastLine="0" shrinkToFit="0" readingOrder="0" />
* <x:protection locked="1" hidden="0" />
* </x:xf>
*/
await NewWriter.WriteStartElementAsync(OldReader.Prefix, "xf", OldReader.NamespaceURI).ConfigureAwait(false);
await NewWriter.WriteAttributeStringAsync(null, "numFmtId", null, "21").ConfigureAwait(false);
await NewWriter.WriteAttributeStringAsync(null, "numFmtId", null, "46").ConfigureAwait(false);
await NewWriter.WriteAttributeStringAsync(null, "fontId", null, $"{Context.OldElementInfos.FontCount}").ConfigureAwait(false);
await NewWriter.WriteAttributeStringAsync(null, "fillId", null, $"{Context.OldElementInfos.FillCount}").ConfigureAwait(false);
await NewWriter.WriteAttributeStringAsync(null, "borderId", null, $"{Context.OldElementInfos.BorderCount + 1}").ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected override async Task GenerateCellXfAsync()
* <x:xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" />
* <x:xf numFmtId="14" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1" />
* <x:xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" />
* <x:xf numFmtId="21" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1" />
* <x:xf numFmtId="46" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1" />
* */

for (int i = 0; i < 3; i++)
Expand Down Expand Up @@ -115,7 +115,7 @@ protected override async Task GenerateCellXfAsync()
await NewWriter.WriteAttributeStringAsync(null, "xfId", null, "0").ConfigureAwait(false);
await NewWriter.WriteEndElementAsync().ConfigureAwait(false);
await NewWriter.WriteStartElementAsync(OldReader.Prefix, "xf", OldReader.NamespaceURI).ConfigureAwait(false);
await NewWriter.WriteAttributeStringAsync(null, "numFmtId", null, "21").ConfigureAwait(false);
await NewWriter.WriteAttributeStringAsync(null, "numFmtId", null, "46").ConfigureAwait(false);
await NewWriter.WriteAttributeStringAsync(null, "applyNumberFormat", null, "1").ConfigureAwait(false);
await NewWriter.WriteEndElementAsync().ConfigureAwait(false);

Expand Down
5 changes: 0 additions & 5 deletions src/MiniExcel.OpenXml/Writer/OpenXmlWriter.XmlGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ internal partial class OpenXmlWriter
private const string FillCellStyleIndex = "4";
private const string TimeCellStyleIndex = "5";

private static readonly DateTime ExcelZeroDate = new(1899, 12, 31);

private readonly Dictionary<string, string> _zipContentsMap = [];
private readonly Dictionary<string, int> _sharedStrings = [];

Expand Down Expand Up @@ -357,9 +355,6 @@ private static double CorrectDateTimeValue(DateTime value)

private (string, string, string) GetTimeSpanValue(TimeSpan value, MiniExcelColumnMapping? columnMapping)
{
if (value.TotalDays >= 1)
return GetDateTimeValue(ExcelZeroDate + value, columnMapping);

var cellValue = value.TotalDays.ToString(CultureInfo.InvariantCulture);
var format = columnMapping?.ExcelFormatId is { } fmt and not -1 ? fmt.ToString() : TimeCellStyleIndex;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ static MiniExcelOpenXmlExporterTests()
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
}

[Fact]
public void TimeSpanOfADayOrMoreStaysADuration()
{
using var path = AutoDeletingPath.Create();
_excelExporter.Export(path.ToString(), new[] { new { Duration = TimeSpan.FromHours(36.25) } });

var row = _excelImporter.Query(path.ToString(), true).First();
Assert.Equal(TimeSpan.FromHours(36.25), (TimeSpan)row.Duration);
}

[Fact]
public void SaveAsControlChracter()
{
Expand Down