Skip to content

Commit 33fd7df

Browse files
committed
[Bug] Fixed when CultureInfo likesff-Latn , datareader field type is datetime that will get error OA Date format #343
1 parent 7c065eb commit 33fd7df

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
### 1.24.3
2626
- [Bug] Fixed multiple threads Async error 'The given key N was not present in the dictionary' #344
27+
- [Bug] Fixed when CultureInfo likes`ff-Latn` , datareader field type is datetime that will get error OA Date format #343
2728

2829
### 1.24.2
2930
- [Bug] Fiexd Query multiple same title will cause startcell to get wrong column index #I4YCLQ

docs/README.zh-CN.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
### 1.24.3
3636
- [Bug] 修正多 threads Async 可能错误 'The given key N was not present in the dictionary' #344
37+
- [Bug] 修正当 CultureInfo 像是`ff-Latn` , datareader field 类型是 datetime 系统会生成错误 OA Date 格式 #343
3738

3839
### 1.24.2
3940
- [Bug] Query 有多个相同标题会导致StartCell无法正确取得该栏位 #I4YCLQ

docs/README.zh-Hant.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
### 1.24.3
2828
- [Bug] 修正多 threads Async 可能錯誤 'The given key N was not present in the dictionary' #344
29+
- [Bug] 修正當 CultureInfo 像是`ff-Latn` , datareader field 類型是 datetime 系統會生成錯誤 OA Date 格式 #343
2930

3031
### 1.24.2
3132
- [Bug] Query<T> 有多個相同標題會導致StartCell無法正確取得該欄位 #I4YCLQ

src/MiniExcel/OpenXml/ExcelOpenXmlSheetWriter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,17 +467,18 @@ private void WriteCell(StreamWriter writer, int rowIndex, int cellIndex, object
467467
{
468468
t = null;
469469
s = "3";
470-
v = ((DateTime)value).ToOADate().ToString();
470+
v = ((DateTime)value).ToOADate().ToString(CultureInfo.InvariantCulture);
471471
}
472472
else
473473
{
474474
// TODO: now it'll lose date type information
475475
t = "str";
476-
v = ((DateTime)value).ToString(p.ExcelFormat);
476+
v = ((DateTime)value).ToString(p.ExcelFormat,_configuration.Culture);
477477
}
478478
}
479479
else
480480
{
481+
//TODO: _configuration.Culture
481482
v = ExcelOpenXmlUtils.EncodeXML(value.ToString());
482483
}
483484
}

tests/MiniExcelTests/MiniExcelIssueTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
using System.Text.RegularExpressions;
2222
using MiniExcelLibs.Csv;
2323
using System.Threading.Tasks;
24+
using System.Data.SqlClient;
2425

2526
namespace MiniExcelLibs.Tests
2627
{
28+
2729
public partial class MiniExcelIssueTests
2830
{
2931
private readonly ITestOutputHelper output;
@@ -32,6 +34,32 @@ public MiniExcelIssueTests(ITestOutputHelper output)
3234
this.output = output;
3335
}
3436

37+
/// <summary>
38+
/// Excel was unable to open the file https://github.com/shps951023/MiniExcel/issues/343
39+
/// </summary>
40+
[Fact]
41+
public void TestIssue343()
42+
{
43+
{
44+
var date = DateTime.Parse("2022-03-17 09:32:06.111", CultureInfo.InvariantCulture);
45+
var path = PathHelper.GetTempFilePath();
46+
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("ff-Latn");
47+
DataTable table = new DataTable();
48+
{
49+
table.Columns.Add("time1", typeof(DateTime));
50+
table.Columns.Add("time2", typeof(DateTime));
51+
table.Rows.Add(date, date);
52+
table.Rows.Add(date, date);
53+
}
54+
DataTableReader reader = table.CreateDataReader();
55+
MiniExcel.SaveAs(path, reader);
56+
57+
var rows = MiniExcel.Query(path,true).ToArray();
58+
Assert.Equal(date, rows[0].time1);
59+
Assert.Equal(date, rows[0].time2);
60+
}
61+
}
62+
3563
[Fact]
3664
public void TestIssueI4YCLQ_2()
3765
{

0 commit comments

Comments
 (0)