From 8eb67b45d57d67d4e273f051bfe194ef09559284 Mon Sep 17 00:00:00 2001 From: Max Zheng <34936931+maxzh1999tw@users.noreply.github.com> Date: Sat, 3 Feb 2024 10:32:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=20API=20=E5=B8=B3=E8=99=9F?= =?UTF-8?q?=E7=B3=BB=E7=B5=B1=E8=88=87=E5=88=9D=E6=AD=A5=20Restful=20API?= =?UTF-8?q?=20=E5=98=97=E8=A9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Plugins/ErrorRecordPluginExtention.cs | 26 +++++++++++++++++++ Excely.sln | 6 +++++ Excely/Plugins/ErrorRecordPlugin.cs | 19 ++++++++++++++ .../ClassListTableConverter.cs | 8 +++--- Excely/Workflows/ExcelyImporterBase.cs | 4 +++ 5 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 Excely.EPPlus.LGPL/Plugins/ErrorRecordPluginExtention.cs create mode 100644 Excely/Plugins/ErrorRecordPlugin.cs diff --git a/Excely.EPPlus.LGPL/Plugins/ErrorRecordPluginExtention.cs b/Excely.EPPlus.LGPL/Plugins/ErrorRecordPluginExtention.cs new file mode 100644 index 0000000..9c4dce1 --- /dev/null +++ b/Excely.EPPlus.LGPL/Plugins/ErrorRecordPluginExtention.cs @@ -0,0 +1,26 @@ +using Excely.Plugins; +using OfficeOpenXml; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Excely.EPPlus.LGPL.Plugins +{ + public static class ErrorRecordPluginExtention + { + public static ExcelWorksheet ExportToWorksheet(this ErrorRecordPlugin errorRecordPlugin, bool errorRowOnly) + { + if(errorRecordPlugin?.Table == null) + { + throw new ArgumentNullException(); + } + + for(int rowIndex = 0; rowIndex < errorRecordPlugin.Table.MaxRowCount; rowIndex++) + { + if(!errorRecordPlugin.Errors.Keys.Any(cell => cell.Row == row)) + } + } + } +} diff --git a/Excely.sln b/Excely.sln index e1d14a8..63fe4e6 100644 --- a/Excely.sln +++ b/Excely.sln @@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Excely.ClosedXML.UnitTests" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{05E1BF0C-B2F1-41C1-B5AB-52C001A3D557}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Debug", "Debug\Debug.csproj", "{7BCFF4FE-F23D-4BDC-8D32-E22148C29F08}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -41,6 +43,10 @@ Global {075DACAA-3E1D-46E6-B094-0E119B56673B}.Debug|Any CPU.Build.0 = Debug|Any CPU {075DACAA-3E1D-46E6-B094-0E119B56673B}.Release|Any CPU.ActiveCfg = Release|Any CPU {075DACAA-3E1D-46E6-B094-0E119B56673B}.Release|Any CPU.Build.0 = Release|Any CPU + {7BCFF4FE-F23D-4BDC-8D32-E22148C29F08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7BCFF4FE-F23D-4BDC-8D32-E22148C29F08}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7BCFF4FE-F23D-4BDC-8D32-E22148C29F08}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7BCFF4FE-F23D-4BDC-8D32-E22148C29F08}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Excely/Plugins/ErrorRecordPlugin.cs b/Excely/Plugins/ErrorRecordPlugin.cs new file mode 100644 index 0000000..6b46083 --- /dev/null +++ b/Excely/Plugins/ErrorRecordPlugin.cs @@ -0,0 +1,19 @@ +namespace Excely.Plugins +{ + public class ErrorRecordPlugin + { + public ExcelyTable? Table { get; set; } + + public Dictionary Errors { get; set; } = new Dictionary(); + + public void DoAfterGetTable(ExcelyTable table) + { + Table = table; + } + + public void RecordError(CellLocation location, string errorMessage) + { + Errors[location] = errorMessage; + } + } +} diff --git a/Excely/TableConverters/ClassListTableConverter.cs b/Excely/TableConverters/ClassListTableConverter.cs index dbbfc98..cdc64a0 100644 --- a/Excely/TableConverters/ClassListTableConverter.cs +++ b/Excely/TableConverters/ClassListTableConverter.cs @@ -92,11 +92,11 @@ private IEnumerable ImportInternal(ExcelyTable table, Func ImportInternal(ExcelyTable table, Func { protected abstract ExcelyTable GetTable(TInput input); + public List> DoAfterGetTableCallbackList { get; set; } = new List>(); + /// /// 將資料匯入為物件列表。 /// @@ -23,6 +25,7 @@ public IEnumerable ToClassList( where TClass : class, new() { var table = GetTable(dataSource); + DoAfterGetTableCallbackList.ForEach(x => x.Invoke(table)); var converter = options == null ? new ClassListTableConverter() : new ClassListTableConverter(options); return converter.ConvertFrom(table); } @@ -38,6 +41,7 @@ public IEnumerable ToClassList( DictionaryListTableConverterOptions? options = null) { var table = GetTable(dataSource); + DoAfterGetTableCallbackList.ForEach(x => x.Invoke(table)); var converter = options == null ? new DictionaryListTableConverter() : new DictionaryListTableConverter(options); return converter.ConvertFrom(table); }