Make System.DateOnly available as date in Excel (#576)

* Format the code and remove trailing whitespaces

* Update Visual Studio gitignore template

* Refactor: rename variables, add comments

* Support writing DateOnly type to Excel

---------

Co-authored-by: Jef Van den Brandt <Jef.VandenBrandt@cheops.be>
This commit is contained in:
Jef 2024-03-31 17:49:31 +02:00 committed by GitHub
parent 9eb23d9bdf
commit b27b169e2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
52 changed files with 610 additions and 473 deletions

179
.gitignore vendored
View File

@ -1,7 +1,10 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
@ -10,6 +13,9 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
@ -17,42 +23,62 @@
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015 cache/options directory
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_i.h
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
@ -62,7 +88,9 @@ artifacts/
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.tlog
*.vspscc
*.vssscc
.builds
@ -90,6 +118,9 @@ ipch/
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
@ -101,15 +132,25 @@ _ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*.json
coverage*.xml
coverage*.info
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
@ -141,9 +182,9 @@ publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
@ -153,13 +194,15 @@ PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
@ -176,12 +219,15 @@ AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
!?*.[Cc]ache/
# Others
ClientBin/
@ -192,9 +238,12 @@ ClientBin/
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
@ -209,15 +258,22 @@ _UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
@ -227,6 +283,7 @@ FakesAssemblies/
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
@ -234,6 +291,20 @@ FakesAssemblies/
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio 6 auto-generated project file (contains which files were open etc.)
*.vbp
# Visual Studio 6 workspace and project file (working project files containing files to include in project)
*.dsw
*.dsp
# Visual Studio 6 technical files
*.ncb
*.aps
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
@ -249,17 +320,83 @@ paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# Visual Studio History (VSHistory) files
.vshistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
# Local History for Visual Studio Code
.history/
# Windows Installer files from build outputs
*.cab
*.msi
*.msix
*.msm
*.msp
# JetBrains Rider
*.sln.iml
/BenchmarkDotNet.Artifacts
/tests/MiniExcel.Tests.AspNetMvc/packages
/TestTemplate

View File

@ -1,5 +1,5 @@
using System;
using MiniExcelLibs.Utils;
using MiniExcelLibs.Utils;
using System;
namespace MiniExcelLibs.Attributes
{

View File

@ -1,6 +1,5 @@
namespace MiniExcelLibs.Attributes
{
using MiniExcelLibs.Utils;
using System;
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public class ExcelColumnNameAttribute : Attribute

View File

@ -2,7 +2,6 @@ using MiniExcelLibs.OpenXml;
using MiniExcelLibs.Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;

View File

@ -1,10 +1,9 @@
namespace MiniExcelLibs
{
using MiniExcelLibs.Csv;
using MiniExcelLibs.OpenXml;
using System;
using MiniExcelLibs.Csv;
using System.IO;
using System.Globalization;
internal class ExcelReaderFactory
{

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MiniExcelLibs.Exceptions
{

View File

@ -1,9 +1,5 @@
using System;
using MiniExcelLibs.Utils;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

View File

@ -1,5 +1,4 @@
using System.IO;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;
namespace MiniExcelLibs

View File

@ -1,5 +1,4 @@
using System.IO;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;
namespace MiniExcelLibs

View File

@ -1,12 +1,12 @@
namespace MiniExcelLibs
{
using Utils;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Utils;
public static partial class MiniExcel
{
@ -57,7 +57,8 @@
public static async Task<IEnumerable<dynamic>> QueryAsync(this Stream stream, bool useHeaderRow = false, string sheetName = null, ExcelType excelType = ExcelType.UNKNOWN, string startCell = "A1", IConfiguration configuration = null, CancellationToken cancellationToken = default(CancellationToken))
{
TaskCompletionSource<IEnumerable<dynamic>> tcs = new TaskCompletionSource<IEnumerable<dynamic>>();
cancellationToken.Register(() => {
cancellationToken.Register(() =>
{
tcs.TrySetCanceled();
});

View File

@ -1,8 +1,5 @@
namespace MiniExcelLibs
{
using System;
using System.Linq;
public static partial class MiniExcel
{
public static string LISENCE_CODE = null;

View File

@ -8,8 +8,6 @@
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Utils;
using Zip;

View File

@ -1,6 +1,5 @@
namespace MiniExcelLibs
{
using MiniExcelLibs.Utils;
using System;
using System.Collections.Generic;
using System.Data;

View File

@ -54,4 +54,9 @@ Todo : https://github.com/mini-software/MiniExcel/projects/1?fullscreen=true</De
<ItemGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Portable.System.DateTimeOnly">
<Version>8.0.0</Version>
</PackageReference>
</ItemGroup>
</Project>

View File

@ -1,10 +1,6 @@
using MiniExcelLibs.Zip;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Xml;
namespace MiniExcelLibs.OpenXml
{

View File

@ -9,8 +9,6 @@ using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static MiniExcelLibs.Utils.ImageHelper;
namespace MiniExcelLibs.OpenXml
@ -382,9 +380,9 @@ namespace MiniExcelLibs.OpenXml
writer.Write($"<x:row r=\"{yIndex}\">");
var cellIndex = xIndex;
foreach (var p in props)
foreach (var columnInfo in props)
{
if (p == null) //reason:https://github.com/shps951023/MiniExcel/issues/142
if (columnInfo == null) //reason:https://github.com/shps951023/MiniExcel/issues/142
{
cellIndex++;
continue;
@ -392,20 +390,20 @@ namespace MiniExcelLibs.OpenXml
object cellValue = null;
if (isDic)
{
cellValue = ((IDictionary)v)[p.Key];
cellValue = ((IDictionary)v)[columnInfo.Key];
//WriteCell(writer, yIndex, cellIndex, cellValue, null); // why null because dictionary that needs to check type every time
//TODO: user can specefic type to optimize efficiency
}
else if (isDapperRow)
{
cellValue = ((IDictionary<string, object>)v)[p.Key.ToString()];
cellValue = ((IDictionary<string, object>)v)[columnInfo.Key.ToString()];
}
else
{
cellValue = p.Property.GetValue(v);
cellValue = columnInfo.Property.GetValue(v);
}
WriteCell(writer, yIndex, cellIndex, cellValue, p);
WriteCell(writer, yIndex, cellIndex, cellValue, columnInfo);
cellIndex++;
}
@ -416,54 +414,57 @@ namespace MiniExcelLibs.OpenXml
return yIndex - 1;
}
private void WriteCell(MiniExcelStreamWriter writer, int rowIndex, int cellIndex, object value, ExcelColumnInfo p)
private void WriteCell(MiniExcelStreamWriter writer, int rowIndex, int cellIndex, object value, ExcelColumnInfo columnInfo)
{
var columname = ExcelOpenXmlUtils.ConvertXyToCell(cellIndex, rowIndex);
var s = "2";
var valueIsNull = value is null || value is DBNull;
if (_configuration.EnableWriteNullValueCell && valueIsNull)
{
writer.Write($"<x:c r=\"{columname}\" s=\"{s}\"></x:c>");
writer.Write($"<x:c r=\"{columname}\" s=\"2\"></x:c>"); // s: style index
return;
}
var tuple = GetCellValue(rowIndex, cellIndex, value, p, valueIsNull);
var tuple = GetCellValue(rowIndex, cellIndex, value, columnInfo, valueIsNull);
s = tuple.Item1;
var t = tuple.Item2;
var v = tuple.Item3;
var styleIndex = tuple.Item1; // https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.cell?view=openxml-3.0.1
var dataType = tuple.Item2; // https://learn.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.cellvalues?view=openxml-3.0.1
var cellValue = tuple.Item3;
if (v != null && (v.StartsWith(" ", StringComparison.Ordinal) || v.EndsWith(" ", StringComparison.Ordinal))) /*Prefix and suffix blank space will lost after SaveAs #294*/
writer.Write($"<x:c r=\"{columname}\" {(t == null ? "" : $"t =\"{t}\"")} s=\"{s}\" xml:space=\"preserve\"><x:v>{v}</x:v></x:c>");
if (cellValue != null && (cellValue.StartsWith(" ", StringComparison.Ordinal) || cellValue.EndsWith(" ", StringComparison.Ordinal))) /*Prefix and suffix blank space will lost after SaveAs #294*/
{
writer.Write($"<x:c r=\"{columname}\" {(dataType == null ? "" : $"t =\"{dataType}\"")} s=\"{styleIndex}\" xml:space=\"preserve\"><x:v>{cellValue}</x:v></x:c>");
}
else
{
//t check avoid format error ![image](https://user-images.githubusercontent.com/12729184/118770190-9eee3480-b8b3-11eb-9f5a-87a439f5e320.png)
writer.Write($"<x:c r=\"{columname}\" {(t == null ? "" : $"t =\"{t}\"")} s=\"{s}\"><x:v>{v}</x:v></x:c>");
writer.Write($"<x:c r=\"{columname}\" {(dataType == null ? "" : $"t =\"{dataType}\"")} s=\"{styleIndex}\"><x:v>{cellValue}</x:v></x:c>");
}
}
private Tuple<string, string, string> GetCellValue(int rowIndex, int cellIndex, object value, ExcelColumnInfo p, bool valueIsNull)
private Tuple<string, string, string> GetCellValue(int rowIndex, int cellIndex, object value, ExcelColumnInfo columnInfo, bool valueIsNull)
{
var s = "2";
var v = string.Empty;
var t = "str";
var styleIndex = "2"; // format code: 0.00
var cellValue = string.Empty;
var dataType = "str";
if (valueIsNull)
{
// use defaults
}
else if (value is string str)
{
v = ExcelOpenXmlUtils.EncodeXML(str);
cellValue = ExcelOpenXmlUtils.EncodeXML(str);
}
else if (p?.ExcelFormat != null && value is IFormattable formattableValue)
else if (columnInfo?.ExcelFormat != null && value is IFormattable formattableValue)
{
var formattedStr = formattableValue.ToString(p.ExcelFormat, _configuration.Culture);
v = ExcelOpenXmlUtils.EncodeXML(formattedStr);
var formattedStr = formattableValue.ToString(columnInfo.ExcelFormat, _configuration.Culture);
cellValue = ExcelOpenXmlUtils.EncodeXML(formattedStr);
}
else
{
Type type = null;
if (p == null || p.Key != null)
Type type;
if (columnInfo == null || columnInfo.Key != null)
{
// TODO: need to optimize
// Dictionary need to check type every time, so it's slow..
@ -472,52 +473,52 @@ namespace MiniExcelLibs.OpenXml
}
else
{
type = p.ExcludeNullableType; //sometime it doesn't need to re-get type like prop
type = columnInfo.ExcludeNullableType; //sometime it doesn't need to re-get type like prop
}
if (type.IsEnum)
{
t = "str";
dataType = "str";
var description = CustomPropertyHelper.DescriptionAttr(type, value); //TODO: need to optimze
if (description != null)
v = description;
cellValue = description;
else
v = value.ToString();
cellValue = value.ToString();
}
else if (TypeHelper.IsNumericType(type))
{
if (_configuration.Culture != CultureInfo.InvariantCulture)
t = "str"; //TODO: add style format
dataType = "str"; //TODO: add style format
else
t = "n";
dataType = "n";
if (type.IsAssignableFrom(typeof(decimal)))
v = ((decimal)value).ToString(_configuration.Culture);
cellValue = ((decimal)value).ToString(_configuration.Culture);
else if (type.IsAssignableFrom(typeof(Int32)))
v = ((Int32)value).ToString(_configuration.Culture);
cellValue = ((Int32)value).ToString(_configuration.Culture);
else if (type.IsAssignableFrom(typeof(Double)))
v = ((Double)value).ToString(_configuration.Culture);
cellValue = ((Double)value).ToString(_configuration.Culture);
else if (type.IsAssignableFrom(typeof(Int64)))
v = ((Int64)value).ToString(_configuration.Culture);
cellValue = ((Int64)value).ToString(_configuration.Culture);
else if (type.IsAssignableFrom(typeof(UInt32)))
v = ((UInt32)value).ToString(_configuration.Culture);
cellValue = ((UInt32)value).ToString(_configuration.Culture);
else if (type.IsAssignableFrom(typeof(UInt16)))
v = ((UInt16)value).ToString(_configuration.Culture);
cellValue = ((UInt16)value).ToString(_configuration.Culture);
else if (type.IsAssignableFrom(typeof(UInt64)))
v = ((UInt64)value).ToString(_configuration.Culture);
cellValue = ((UInt64)value).ToString(_configuration.Culture);
else if (type.IsAssignableFrom(typeof(Int16)))
v = ((Int16)value).ToString(_configuration.Culture);
cellValue = ((Int16)value).ToString(_configuration.Culture);
else if (type.IsAssignableFrom(typeof(Single)))
v = ((Single)value).ToString(_configuration.Culture);
cellValue = ((Single)value).ToString(_configuration.Culture);
else if (type.IsAssignableFrom(typeof(Single)))
v = ((Single)value).ToString(_configuration.Culture);
cellValue = ((Single)value).ToString(_configuration.Culture);
else
v = (decimal.Parse(value.ToString())).ToString(_configuration.Culture);
cellValue = (decimal.Parse(value.ToString())).ToString(_configuration.Culture);
}
else if (type == typeof(bool))
{
t = "b";
v = (bool)value ? "1" : "0";
dataType = "b";
cellValue = (bool)value ? "1" : "0";
}
else if (type == typeof(byte[]) && _configuration.EnableConvertByteArray)
{
@ -549,38 +550,61 @@ namespace MiniExcelLibs.OpenXml
//TODO:Convert to base64
var base64 = $"@@@fileid@@@,{file.Path}";
v = ExcelOpenXmlUtils.EncodeXML(base64);
s = "4";
cellValue = ExcelOpenXmlUtils.EncodeXML(base64);
styleIndex = "4";
}
}
else if (type == typeof(DateTime))
{
if (_configuration.Culture != CultureInfo.InvariantCulture)
{
t = "str";
v = ((DateTime)value).ToString(_configuration.Culture);
dataType = "str";
cellValue = ((DateTime)value).ToString(_configuration.Culture);
}
else if (p == null || p.ExcelFormat == null)
else if (columnInfo == null || columnInfo.ExcelFormat == null)
{
t = null;
s = "3";
v = ((DateTime)value).ToOADate().ToString(CultureInfo.InvariantCulture);
dataType = null;
styleIndex = "3";
cellValue = ((DateTime)value).ToOADate().ToString(CultureInfo.InvariantCulture);
}
else
{
// TODO: now it'll lose date type information
t = "str";
v = ((DateTime)value).ToString(p.ExcelFormat, _configuration.Culture);
dataType = "str";
cellValue = ((DateTime)value).ToString(columnInfo.ExcelFormat, _configuration.Culture);
}
}
#if NETSTANDARD2_0_OR_GREATER
else if (type == typeof(DateOnly))
{
if (_configuration.Culture != CultureInfo.InvariantCulture)
{
dataType = "str";
cellValue = ((DateOnly)value).ToString(_configuration.Culture);
}
else if (columnInfo == null || columnInfo.ExcelFormat == null)
{
var day = (DateOnly)value;
dataType = "n";
styleIndex = "3";
cellValue = day.ToDateTime(TimeOnly.MinValue).ToOADate().ToString(CultureInfo.InvariantCulture);
}
else
{
// TODO: now it'll lose date type information
dataType = "str";
cellValue = ((DateOnly)value).ToString(columnInfo.ExcelFormat, _configuration.Culture);
}
}
#endif
else
{
//TODO: _configuration.Culture
v = ExcelOpenXmlUtils.EncodeXML(value.ToString());
cellValue = ExcelOpenXmlUtils.EncodeXML(value.ToString());
}
}
return Tuple.Create(s, t, v);
return Tuple.Create(styleIndex, dataType, cellValue);
}
private void GenerateSheetByDataTable(MiniExcelStreamWriter writer, DataTable value)
@ -631,7 +655,7 @@ namespace MiniExcelLibs.OpenXml
for (int j = 0; j < value.Columns.Count; j++)
{
var cellValue = value.Rows[i][j];
WriteCell(writer, yIndex, xIndex, cellValue, null);
WriteCell(writer, yIndex, xIndex, cellValue, columnInfo: null);
xIndex++;
}
writer.Write($"</x:row>");
@ -683,7 +707,7 @@ namespace MiniExcelLibs.OpenXml
for (int i = 0; i < fieldCount; i++)
{
var cellValue = reader.GetValue(i);
WriteCell(writer, yIndex, xIndex, cellValue, null);
WriteCell(writer, yIndex, xIndex, cellValue, columnInfo: null);
xIndex++;
}
writer.Write($"</x:row>");

View File

@ -950,9 +950,12 @@ namespace MiniExcelLibs.OpenXml
foreach (var p in props)
{
values.Add(p.Name, new PropInfo { PropertyInfo = p,
values.Add(p.Name, new PropInfo
{
PropertyInfo = p,
PropertyInfoOrFieldInfo = PropertyInfoOrFieldInfo.PropertyInfo,
UnderlyingTypePropType = Nullable.GetUnderlyingType(p.PropertyType) ?? p.PropertyType });
UnderlyingTypePropType = Nullable.GetUnderlyingType(p.PropertyType) ?? p.PropertyType
});
}
var fields = xRowInfo.IEnumerableGenricType.GetFields();
@ -961,9 +964,12 @@ namespace MiniExcelLibs.OpenXml
if (!values.ContainsKey(f.Name))
{
values.Add(f.Name, new PropInfo { FieldInfo = f,
values.Add(f.Name, new PropInfo
{
FieldInfo = f,
PropertyInfoOrFieldInfo = PropertyInfoOrFieldInfo.FieldInfo,
UnderlyingTypePropType = Nullable.GetUnderlyingType(f.FieldType) ?? f.FieldType });
UnderlyingTypePropType = Nullable.GetUnderlyingType(f.FieldType) ?? f.FieldType
});
}
}

View File

@ -1,4 +1,6 @@
using System;
using MiniExcelLibs.Utils;
using MiniExcelLibs.Zip;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
@ -6,8 +8,6 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MiniExcelLibs.Utils;
using MiniExcelLibs.Zip;
namespace MiniExcelLibs.OpenXml
{

View File

@ -4,14 +4,12 @@ namespace MiniExcelLibs.OpenXml
using MiniExcelLibs.Utils;
using MiniExcelLibs.Zip;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

View File

@ -4,11 +4,11 @@
namespace MiniExcelLibs.OpenXml
{
using System;
using System.IO;
using System.Text;
using System;
using System.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;
internal class MiniExcelAsyncStreamWriter : IDisposable
{

View File

@ -1,8 +1,6 @@
namespace MiniExcelLibs.Utils
{
using MiniExcelLibs.Utils;
using System;
using System.Globalization;
#if DEBUG
public

View File

@ -1,9 +1,5 @@
namespace MiniExcelLibs.Utils
{
using System;
using System.Linq;
using System.Text;
internal class ImageHelper
{
public enum ImageFormat

View File

@ -1,6 +1,5 @@
namespace MiniExcelLibs.Utils
{
using MiniExcelLibs.Attributes;
using MiniExcelLibs.Exceptions;
using System;
using System.Collections.Generic;

View File

@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices.ComTypes;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace MiniExcelLibs.Utils

View File

@ -1,5 +1,4 @@
using System;
using System.IO.Compression;
using System.IO.Compression;
namespace MiniExcelLibs.Zip
{

View File

@ -158,14 +158,16 @@ namespace MiniExcelLibs.Tests
{
var path = PathHelper.GetFile("xls/TestIssue242.xls");
await Assert.ThrowsAsync<NotSupportedException>(async () => {
await Assert.ThrowsAsync<NotSupportedException>(async () =>
{
var q = await MiniExcel.QueryAsync(path);
q.ToList();
});
using (var stream = File.OpenRead(path))
{
await Assert.ThrowsAsync<NotSupportedException>(async () => {
await Assert.ThrowsAsync<NotSupportedException>(async () =>
{
var q = await stream.QueryAsync();
q.ToList();
});

View File

@ -1,10 +1,13 @@
using Dapper;
using MiniExcelLibs.Attributes;
using MiniExcelLibs.Csv;
using MiniExcelLibs.Exceptions;
using MiniExcelLibs.OpenXml;
using MiniExcelLibs.Tests.Utils;
using Newtonsoft.Json;
using OfficeOpenXml;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -13,28 +16,23 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using static MiniExcelLibs.Tests.MiniExcelOpenXmlTests;
using System.Collections;
using MiniExcelLibs.Exceptions;
using System.Text.RegularExpressions;
using MiniExcelLibs.Csv;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace MiniExcelLibs.Tests
{
public partial class MiniExcelIssueTests
{
private readonly ITestOutputHelper output;
public MiniExcelIssueTests(ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void TestIssue24020201()
{
@ -60,9 +58,12 @@ namespace MiniExcelLibs.Tests
{
var path = PathHelper.GetTempFilePath();
var templatePath = PathHelper.GetFile("xlsx/TestIssue553.xlsx");
var data = new { B = new[] {
var data = new
{
B = new[] {
new{ ITM=1 },new{ ITM=2 }, new{ ITM=3 },
} };
}
};
MiniExcel.SaveAsByTemplate(path, templatePath, data);
}

View File

@ -1,21 +1,21 @@
using Xunit;
using System;
using System.Linq;
using System.IO;
using OfficeOpenXml;
using ClosedXML.Excel;
using System.IO.Packaging;
using System.Data;
using ExcelDataReader;
using System.Collections.Generic;
using System.Data.SQLite;
using ClosedXML.Excel;
using Dapper;
using System.Globalization;
using static MiniExcelLibs.Tests.Utils.MiniExcelOpenXml;
using MiniExcelLibs.Tests.Utils;
using ExcelDataReader;
using MiniExcelLibs.Attributes;
using System.Threading.Tasks;
using MiniExcelLibs.Tests.Utils;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Globalization;
using System.IO;
using System.IO.Packaging;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
using static MiniExcelLibs.Tests.Utils.MiniExcelOpenXml;
namespace MiniExcelLibs.Tests
{
@ -1205,7 +1205,8 @@ namespace MiniExcelLibs.Tests
[Fact()]
public async Task ReadBigExcel_TakeCancel_Throws_TaskCanceledException()
{
await Assert.ThrowsAsync<TaskCanceledException>(async () => {
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
{
CancellationTokenSource cts = new CancellationTokenSource();
var path = @"../../../../../samples/xlsx/bigExcel.xlsx";
@ -1222,7 +1223,8 @@ namespace MiniExcelLibs.Tests
[Fact()]
public async Task ReadBigExcel_Prcoessing_TakeCancel_Throws_TaskCanceledException()
{
await Assert.ThrowsAsync<OperationCanceledException>(async () => {
await Assert.ThrowsAsync<OperationCanceledException>(async () =>
{
CancellationTokenSource cts = new CancellationTokenSource();
var path = @"../../../../../samples/xlsx/bigExcel.xlsx";

View File

@ -1,9 +1,9 @@
using Xunit;
using System.Linq;
using System;
using System.IO;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
namespace MiniExcelLibs.Tests
{
@ -35,7 +35,8 @@ namespace MiniExcelLibs.Tests
Assert.Equal(2, rows[0].B);
}
{
await Assert.ThrowsAsync<InvalidOperationException>(async() => {
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
{
var q = await MiniExcel.QueryAsync(path, sheetName: "xxxx");
q.ToList();
});

View File

@ -1,22 +1,22 @@
using Xunit;
using System;
using System.Linq;
using System.IO;
using OfficeOpenXml;
using ClosedXML.Excel;
using System.IO.Packaging;
using System.Data;
using ExcelDataReader;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Diagnostics;
using ClosedXML.Excel;
using Dapper;
using System.Globalization;
using static MiniExcelLibs.Tests.Utils.MiniExcelOpenXml;
using MiniExcelLibs.Tests.Utils;
using ExcelDataReader;
using MiniExcelLibs.Attributes;
using MiniExcelLibs.OpenXml;
using MiniExcelLibs.Tests.Utils;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Packaging;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
using static MiniExcelLibs.Tests.Utils.MiniExcelOpenXml;
namespace MiniExcelLibs.Tests
{

View File

@ -8,8 +8,6 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Xml;
using MiniExcelLibs.OpenXml;
using Xunit;
namespace MiniExcelTests
@ -890,7 +888,8 @@ namespace MiniExcelTests
[Fact()]
public async Task SaveAsByTemplateAsync_TakeCancel_Throws_TaskCanceledException()
{
await Assert.ThrowsAsync<TaskCanceledException>(async () => {
await Assert.ThrowsAsync<TaskCanceledException>(async () =>
{
CancellationTokenSource cts = new CancellationTokenSource();
cts.Cancel();

View File

@ -9,5 +9,4 @@
return new SQLiteConnection(connectionString);
}
}
}

View File

@ -1,6 +1,5 @@
namespace MiniExcelLibs.Tests.Utils
{
using MiniExcelLibs.OpenXml;
using System;
using System.Collections.Generic;
using System.IO;