Skip to content
Merged
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
6 changes: 3 additions & 3 deletions src/MiniExcel.OpenXml/Writer/OpenXmlWriter.XmlGeneration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private string GetFileValue(int rowIndex, int cellIndex, object value)
private (string, string, string) GetDateTimeValue(DateTime value, MiniExcelColumnMapping? columnMapping)
{
string? cellValue;
if (!ReferenceEquals(_configuration.Culture, CultureInfo.InvariantCulture))
if (string.IsNullOrEmpty(columnMapping?.ExcelFormat) && !ReferenceEquals(_configuration.Culture, CultureInfo.InvariantCulture))
{
cellValue = value.ToString(_configuration.Culture);
return (RegularCellStyleIndex, ExcelDataTypes.CalculatedString, cellValue);
Expand All @@ -342,10 +342,10 @@ private static double CorrectDateTimeValue(DateTime value)
// Excel says 1900 was a leap year :( Replicate an incorrect behavior thanks
// to Lotus 1-2-3 decision from 1983...
// https://github.com/ClosedXML/ClosedXML/blob/develop/ClosedXML/Extensions/DateTimeExtensions.cs#L45
const int nonExistent1900Feb29SerialDate = 60;
const double serialDate01March1900 = 61d;

var oaDate = value.ToOADate();
if (oaDate <= nonExistent1900Feb29SerialDate)
if (oaDate < serialDate01March1900)
{
oaDate--;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/MiniExcel.OpenXml.Tests/Issues/MiniExcelGithubIssuesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3400,4 +3400,25 @@ public void FillMergedCellsAppliesTheStyleOfTheFirstCellOfTheMergedRange()
Assert.Equal(3, rows.Count);
Assert.All(rows, row => Assert.Equal(new DateTime(2026, 11, 1), (object)row.A));
}

[Fact]
public async Task TestIssue1073_CultureWithFormatSerializesCorrectly()
{
var date = new DateTime(2026, 11, 25);

var rows = new[] { new Issue1073Dto { Date = date } };
var config = new OpenXmlConfiguration
{
Culture = CultureInfo.GetCultureInfo("ja-JP")
};

using var ms = new MemoryStream();
await _excelExporter.ExportAsync(ms, rows, configuration: config);

ms.Seek(0, SeekOrigin.Begin);
using var wb = new XLWorkbook(ms);
var cell = wb.Worksheet(1).Cell("A2");

Assert.Equal(date, cell.Value.GetDateTime());
}
}
6 changes: 6 additions & 0 deletions tests/MiniExcel.OpenXml.Tests/Issues/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ internal class Issue951Dto
public object this[string? test] => new();
}

public class Issue1073Dto
{
[MiniExcelFormat("yyyy/MM/dd")]
public DateTime Date { get; set; }
}

internal class TestIssueI4YCLQ_2Dto
{
[MiniExcelColumnIndex("A")] public string? 站点编码 { get; set; }
Expand Down
Loading