mirror of
https://gitee.com/dotnetchina/MiniExcel.git
synced 2024-11-29 18:38:08 +08:00
0.17.2
-[Bug] Fix v0.16.0-0.17.1 custom format contains specific format (eg:`#,##0.000_);[Red]\(#,##0.000\)`), automatic converter will convert double to datetime #267
This commit is contained in:
parent
3c03f19a07
commit
0904a80d10
@ -27,7 +27,7 @@ At present, most popular frameworks need to load all the data into the memory to
|
||||
- Support `real-time` operation of each row of data
|
||||
![miniexcel_lazy_load](https://user-images.githubusercontent.com/12729184/111034290-e5588a80-844f-11eb-8c84-6fdb6fb8f403.gif)
|
||||
- Support LINQ deferred execution, it can do low-consumption, fast paging and other complex queries
|
||||
- Lightweight, without Microsoft Office installed, no COM+, third-party dependencies, DLL size is less than 100KB
|
||||
- Lightweight, without Microsoft Office installed, no COM+, third-party dependencies, DLL size is less than 150KB
|
||||
- Easy API style to read/write/fill excel
|
||||
|
||||
### Get Started
|
||||
|
@ -32,7 +32,7 @@ MiniExcel简单、高效避免OOM的.NET处理Excel查、写、填充数据工
|
||||
- 支持`即时`操作每行数据
|
||||
![miniexcel_lazy_load](https://user-images.githubusercontent.com/12729184/111034290-e5588a80-844f-11eb-8c84-6fdb6fb8f403.gif)
|
||||
- 兼具搭配 LINQ 延迟查询特性,能办到低消耗、快速分页等复杂查询
|
||||
- 轻量,不需要安装 Microsoft Office、COM+、不依赖任何套件,DLL小于100KB
|
||||
- 轻量,不需要安装 Microsoft Office、COM+、不依赖任何套件,DLL小于150KB
|
||||
- 简便操作的 API 风格
|
||||
|
||||
|
||||
|
@ -29,7 +29,7 @@ MiniExcel 簡單、高效避免OOM的.NET處理Excel查、寫、填充工具。
|
||||
- 兼具搭配 LINQ 延遲查詢特性,能辦到低消耗、快速分頁等複雜查詢
|
||||
圖片:與主流框架對比的消耗、效率差
|
||||
![20210419](https://user-images.githubusercontent.com/12729184/114679083-6ef4c400-9d3e-11eb-9f78-a86daa45fe46.gif)
|
||||
- 輕量,不需要安裝 Microsoft Office、COM+、不依賴任何套件,DLL小於100KB
|
||||
- 輕量,不需要安裝 Microsoft Office、COM+、不依賴任何套件,DLL小於150KB
|
||||
- 簡便操作的 API 風格
|
||||
|
||||
|
||||
|
@ -16,6 +16,9 @@
|
||||
|
||||
---
|
||||
|
||||
### 0.17.2
|
||||
-[Bug] Fix v0.16.0-0.17.1 custom format contains specific format (eg:`#,##0.000_);[Red]\(#,##0.000\)`), automatic converter will convert double to datetime #267
|
||||
|
||||
### 0.17.1
|
||||
- [New] Add QueryAsDataTableAsync(this Stream stream..)
|
||||
- [OPT] More clear strong type conversion error message [#I3X2ZL](https://gitee.com/dotnetchina/MiniExcel/issues/I3X2ZL)
|
||||
|
@ -23,6 +23,9 @@
|
||||
|
||||
---
|
||||
|
||||
### 0.17.2
|
||||
- [Bug] 修复 v0.16.0-0.17.1 自定义格式含有特定格式(e.g:`#,##0.000_);[Red]\(#,##0.000\)`),自动转换器会将 double 被转成 datetime 异常 #267
|
||||
|
||||
### 0.17.1
|
||||
- [New] 增加 QueryAsDataTableAsync(this Stream stream..)
|
||||
- [OPT] 强型别 Query 转型错误信息能知道在哪一行列出错 [#I3X2ZL](https://gitee.com/dotnetchina/MiniExcel/issues/I3X2ZL)
|
||||
|
@ -17,6 +17,9 @@
|
||||
|
||||
---
|
||||
|
||||
### 0.17.2
|
||||
- [Bug] 修復 v0.16.0-0.17.1 自定義格式含有特定格式(e.g:`#,##0.000_);[Red]\(#,##0.000\)`),自動轉換器會將 double 被轉成 datetime 異常 #267
|
||||
|
||||
### 0.17.1
|
||||
- [New] 增加 QueryAsDataTableAsync(this Stream stream..)
|
||||
- [OPT] 強型別 Query 轉型錯誤訊息能知道在哪一行列出錯 [#I3X2ZL](https://gitee.com/dotnetchina/MiniExcel/issues/I3X2ZL)
|
||||
|
BIN
samples/xlsx/TestIssue267.xlsx
Normal file
BIN
samples/xlsx/TestIssue267.xlsx
Normal file
Binary file not shown.
@ -1,34 +1,39 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net45;netstandard2.0;net5.0</TargetFrameworks>
|
||||
<Version>0.17.1</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyName>MiniExcel</AssemblyName>
|
||||
<Title>MiniExcel</Title>
|
||||
<Product>MiniExcel</Product>
|
||||
<PackageTags>excel;xlsx;micro-helper;mini;openxml;helper;</PackageTags>
|
||||
<Description>A high performance and easy Excel(xlsx,csv) Micro-Helper that avoids OOM and without third-party dependencies to create/query/template-fill-data.
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net45;netstandard2.0;net5.0</TargetFrameworks>
|
||||
<Version>0.17.2</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyName>MiniExcel</AssemblyName>
|
||||
<Title>MiniExcel</Title>
|
||||
<Product>MiniExcel</Product>
|
||||
<PackageTags>excel;xlsx;micro-helper;mini;openxml;helper;</PackageTags>
|
||||
<Description>
|
||||
A high performance and easy Excel(xlsx,csv) Micro-Helper that avoids OOM and without third-party dependencies to create/query/template-fill-data.
|
||||
|
||||
Github : https://github.com/shps951023/MiniExcel
|
||||
Gitee : https://gitee.com/dotnetchina/MiniExcel
|
||||
Issues : https://github.com/shps951023/MiniExcel/issues
|
||||
Todo : https://github.com/shps951023/MiniExcel/projects/1?fullscreen=true
|
||||
</Description>
|
||||
<Authors>ITWeiHan</Authors>
|
||||
<Copyright>©2021 WeiHan Lin</Copyright>
|
||||
<license>https://raw.githubusercontent.com/shps951023/MiniExcel/master/LICENSE.md</license>
|
||||
<PackageLicenseUrl>https://raw.githubusercontent.com/shps951023/MiniExcel/master/LICENSE.md</PackageLicenseUrl>
|
||||
<PackageProjectUrl>https://github.com/shps951023/MiniExcel</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/shps951023/MiniExcel</RepositoryUrl>
|
||||
<PackageIconUrl>https://user-images.githubusercontent.com/12729184/115023335-39440c80-9ef1-11eb-8771-7260d1e50d5a.png</PackageIconUrl>
|
||||
<PackageReleaseNotes>Please Check [Release Notes](https://github.com/shps951023/MiniExcel/tree/master/docs)</PackageReleaseNotes>
|
||||
<RepositoryType>Github</RepositoryType>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net461'">
|
||||
<Reference Include="System.IO.Compression" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net45'">
|
||||
<Reference Include="System.IO.Compression" />
|
||||
</ItemGroup>
|
||||
Github : https://github.com/shps951023/MiniExcel
|
||||
Gitee : https://gitee.com/dotnetchina/MiniExcel
|
||||
Issues : https://github.com/shps951023/MiniExcel/issues
|
||||
Todo : https://github.com/shps951023/MiniExcel/projects/1?fullscreen=true
|
||||
</Description>
|
||||
<Authors>ITWeiHan</Authors>
|
||||
<Copyright>©2021 WeiHan Lin</Copyright>
|
||||
<license>https://raw.githubusercontent.com/shps951023/MiniExcel/master/LICENSE.md</license>
|
||||
<PackageLicenseUrl>https://raw.githubusercontent.com/shps951023/MiniExcel/master/LICENSE.md</PackageLicenseUrl>
|
||||
<PackageProjectUrl>https://github.com/shps951023/MiniExcel</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/shps951023/MiniExcel</RepositoryUrl>
|
||||
<PackageIconUrl>https://user-images.githubusercontent.com/12729184/115023335-39440c80-9ef1-11eb-8771-7260d1e50d5a.png</PackageIconUrl>
|
||||
<PackageReleaseNotes>Please Check [Release Notes](https://github.com/shps951023/MiniExcel/tree/master/docs)</PackageReleaseNotes>
|
||||
<RepositoryType>Github</RepositoryType>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net461'">
|
||||
<Reference Include="System.IO.Compression" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net45'">
|
||||
<Reference Include="System.IO.Compression" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ExcelNumberFormat" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -78,7 +78,7 @@
|
||||
|
||||
//TODO: determine the type according to the format
|
||||
var type = typeof(string);
|
||||
if(DateTimeHelper.isDateTimeFormat(formatCode))
|
||||
if(DateTimeHelper.IsDateTimeFormat(formatCode))
|
||||
{
|
||||
type = typeof(DateTime?);
|
||||
}
|
||||
@ -129,6 +129,11 @@
|
||||
{
|
||||
if (double.TryParse(value?.ToString(), out var s))
|
||||
{
|
||||
//TODO: if format like yyyy, it need to convert to double, not return datetime value
|
||||
|
||||
|
||||
|
||||
|
||||
return DateTimeHelper.FromOADate(s);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,29 @@
|
||||
namespace MiniExcelLibs.Utils
|
||||
{
|
||||
using ExcelNumberFormat;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
internal static partial class DateTimeHelper
|
||||
{
|
||||
private static DateTime basicDate = new DateTime(2021, 01, 01);
|
||||
public static bool isDateTimeFormat(string formatCode)
|
||||
|
||||
/// <summary>
|
||||
/// NumberFormat from NuGet ExcelNumberFormat MIT@License
|
||||
/// </summary>
|
||||
public static bool IsDateTimeFormat(string formatCode)
|
||||
{
|
||||
return new NumberFormat(formatCode).IsDateTimeFormat;
|
||||
}
|
||||
|
||||
public static bool IsSingleDatetimeFormat(string formatCode)
|
||||
{
|
||||
var isDatetimeFormat = DateTime.TryParseExact(basicDate.ToString(formatCode), formatCode, CultureInfo.InvariantCulture, DateTimeStyles.AllowLeadingWhite | DateTimeStyles.AllowTrailingWhite, out var date);
|
||||
//Console.WriteLine($"format {formatCode} formatDate {date}");
|
||||
if (basicDate != date)
|
||||
isDatetimeFormat = false;
|
||||
|
||||
// TODO: double check
|
||||
// TODO: datetime format like yyyy need to convert to string not datetime
|
||||
return isDatetimeFormat;
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,53 @@ namespace MiniExcelLibs.Tests
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// v0.16.0-0.17.1 custom format contains specific format (eg:`#,##0.000_);[Red]\(#,##0.000\)`), automatic converter will convert double to datetime #267
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void TestIssue267()
|
||||
{
|
||||
var path = PathHelper.GetSamplePath("/xlsx/TestIssue267.xlsx");
|
||||
var row = MiniExcel.Query(path).SingleOrDefault();
|
||||
Assert.Equal(10618, row.A);
|
||||
Assert.Equal("2021-02-23", row.B);
|
||||
Assert.Equal(43.199999999999996, row.C);
|
||||
Assert.Equal(1.2, row.D);
|
||||
Assert.Equal(new DateTime(2021, 7, 5), row.E);
|
||||
Assert.Equal(new DateTime(2021, 7, 5,15,2,46), row.F);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void TestIssue268_DateFormat()
|
||||
{
|
||||
Assert.True(IsDateFormatString("dd/mm/yyyy"));
|
||||
Assert.True(IsDateFormatString("dd-mmm-yy"));
|
||||
Assert.True(IsDateFormatString("dd-mmmm"));
|
||||
Assert.True(IsDateFormatString("mmm-yy"));
|
||||
Assert.True(IsDateFormatString("h:mm AM/PM"));
|
||||
Assert.True(IsDateFormatString("h:mm:ss AM/PM"));
|
||||
Assert.True(IsDateFormatString("hh:mm"));
|
||||
Assert.True(IsDateFormatString("hh:mm:ss"));
|
||||
Assert.True(IsDateFormatString("dd/mm/yyyy hh:mm"));
|
||||
Assert.True(IsDateFormatString("mm:ss"));
|
||||
Assert.True(IsDateFormatString("mm:ss.0"));
|
||||
Assert.True(IsDateFormatString("[$-809]dd mmmm yyyy"));
|
||||
Assert.False(IsDateFormatString("#,##0;[Red]-#,##0"));
|
||||
Assert.False(IsDateFormatString(@"#,##0.000_);[Red]\(#,##0.000\)"));
|
||||
Assert.False(IsDateFormatString("0_);[Red](0)"));
|
||||
Assert.False(IsDateFormatString(@"0\h"));
|
||||
Assert.False(IsDateFormatString("0\"h\""));
|
||||
Assert.False(IsDateFormatString("0%"));
|
||||
Assert.False(IsDateFormatString("General"));
|
||||
Assert.False(IsDateFormatString(@"_-* #,##0\ _P_t_s_-;\-* #,##0\ _P_t_s_-;_-* "" - ""??\ _P_t_s_-;_-@_- "));
|
||||
}
|
||||
|
||||
private bool IsDateFormatString(string formatCode)
|
||||
{
|
||||
return MiniExcelLibs.Utils.DateTimeHelper.IsDateTimeFormat(formatCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestIssueI3X2ZL()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user