From e9a2a1b3b493fea90379b0ee519b7bbb42011122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BF=8A?= Date: Wed, 25 Oct 2023 05:45:30 +0000 Subject: [PATCH 01/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=BC=E5=85=A5Strea?= =?UTF-8?q?m=E6=97=B6=E7=9A=84=E5=9B=9E=E8=B0=83=E5=A7=94=E6=89=98?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Magicodes.ExporterAndImporter.Core/IImporter.cs | 2 +- src/Magicodes.ExporterAndImporter.Excel/ExcelImporter.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Magicodes.ExporterAndImporter.Core/IImporter.cs b/src/Magicodes.ExporterAndImporter.Core/IImporter.cs index af631a65..cedce2a8 100644 --- a/src/Magicodes.ExporterAndImporter.Core/IImporter.cs +++ b/src/Magicodes.ExporterAndImporter.Core/IImporter.cs @@ -74,6 +74,6 @@ public interface IImporter /// /// /// - Task> Import(Stream stream,Stream labelingFileStream) where T : class, new(); + Task> Import(Stream stream, Stream labelingFileStream, Func, ImportResult> importResultCallback = null) where T : class, new(); } } \ No newline at end of file diff --git a/src/Magicodes.ExporterAndImporter.Excel/ExcelImporter.cs b/src/Magicodes.ExporterAndImporter.Excel/ExcelImporter.cs index 474d0942..2f2186e7 100644 --- a/src/Magicodes.ExporterAndImporter.Excel/ExcelImporter.cs +++ b/src/Magicodes.ExporterAndImporter.Excel/ExcelImporter.cs @@ -169,11 +169,11 @@ public class ExcelImporter : IExcelImporter /// /// /// - public Task> Import(Stream stream, Stream labelingFileStream) where T : class, new() + public Task> Import(Stream stream, Stream labelingFileStream, Func, ImportResult> importResultCallback = null) where T : class, new() { using (var importer = new ImportHelper(stream, labelingFileStream)) { - return importer.Import(); + return importer.Import(importResultCallback: importResultCallback); } } From 36a0bfb2369f34f0a815cd3839d22e8a3e32e857 Mon Sep 17 00:00:00 2001 From: netty2019 <1025556487@qq.com> Date: Fri, 29 Dec 2023 16:56:51 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ValueMappingsBase?= =?UTF-8?q?=E5=80=BC=E6=98=A0=E5=B0=84=E7=89=B9=E6=80=A7=E5=9F=BA=E7=B1=BB?= =?UTF-8?q?=EF=BC=8C=E6=96=B9=E4=BE=BF=E4=BB=8E=E5=A4=96=E9=83=A8(?= =?UTF-8?q?=E5=A6=82=EF=BC=9AAbp=E6=A1=86=E6=9E=B6)=E7=BB=A7=E6=89=BF?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=9E=9A=E4=B8=BE=E3=80=81bool=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E5=A4=9A=E8=AF=AD=E8=A8=80=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extension/Extension.cs | 8 ++++++++ .../ValueMappingsBaseAttribute.cs | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs diff --git a/src/Magicodes.ExporterAndImporter.Core/Extension/Extension.cs b/src/Magicodes.ExporterAndImporter.Core/Extension/Extension.cs index 1bf9f1de..819f3cc5 100644 --- a/src/Magicodes.ExporterAndImporter.Core/Extension/Extension.cs +++ b/src/Magicodes.ExporterAndImporter.Core/Extension/Extension.cs @@ -322,7 +322,15 @@ public static int GetLargestContinuous(this List numList) public static void ValueMapping(this PropertyInfo propertyInfo, ref Dictionary directory) { #region 处理值映射 + //ValueMappingsBaseAttribute + var valueMappings = propertyInfo.GetAttributes(true).FirstOrDefault()?.GetMappings(propertyInfo.PropertyType); + foreach (var valueMapping in valueMappings) + { + if (!directory.ContainsKey(valueMapping.Key)) directory.Add(valueMapping.Key, valueMapping.Value); + } + if (valueMappings != null && valueMappings.Count > 0) return; + //ValueMappingAttribute var mappings = propertyInfo.GetAttributes().ToList(); var objects = directory; foreach (var mappingAttribute in mappings.Where(mappingAttribute => diff --git a/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs b/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs new file mode 100644 index 00000000..ecd56562 --- /dev/null +++ b/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Magicodes.IE.Core +{ + /// + /// 值映射 + /// + [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] + public abstract class ValueMappingsBaseAttribute : Attribute + { + /// + /// 根据字段类型获取映射 + /// + /// + /// + public abstract Dictionary GetMappings(Type fieldType); + } +} From 88b1acfd1b9299e05797da3df8d6b721a18b7258 Mon Sep 17 00:00:00 2001 From: netty <1025556487@qq.com> Date: Sat, 30 Dec 2023 14:38:04 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ValueMappingsBase?= =?UTF-8?q?=E5=80=BC=E6=98=A0=E5=B0=84=E7=89=B9=E6=80=A7=E5=9F=BA=E7=B1=BB?= =?UTF-8?q?=EF=BC=8C=E6=96=B9=E4=BE=BF=E4=BB=8E=E5=A4=96=E9=83=A8(?= =?UTF-8?q?=E5=A6=82=EF=BC=9AAbp=E6=A1=86=E6=9E=B6)=E7=BB=A7=E6=89=BF?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=9E=9A=E4=B8=BE=E3=80=81bool=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E5=A4=9A=E8=AF=AD=E8=A8=80=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extension/Extension.cs | 2 +- .../ValueMappingsBaseAttribute.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Magicodes.ExporterAndImporter.Core/Extension/Extension.cs b/src/Magicodes.ExporterAndImporter.Core/Extension/Extension.cs index 819f3cc5..2ea2482e 100644 --- a/src/Magicodes.ExporterAndImporter.Core/Extension/Extension.cs +++ b/src/Magicodes.ExporterAndImporter.Core/Extension/Extension.cs @@ -323,7 +323,7 @@ public static void ValueMapping(this PropertyInfo propertyInfo, ref Dictionary(true).FirstOrDefault()?.GetMappings(propertyInfo.PropertyType); + var valueMappings = propertyInfo.GetAttributes(true).FirstOrDefault()?.GetMappings(propertyInfo); foreach (var valueMapping in valueMappings) { if (!directory.ContainsKey(valueMapping.Key)) directory.Add(valueMapping.Key, valueMapping.Value); diff --git a/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs b/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs index ecd56562..f01298a7 100644 --- a/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs +++ b/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Reflection; using System.Text; namespace Magicodes.IE.Core @@ -13,8 +14,8 @@ public abstract class ValueMappingsBaseAttribute : Attribute /// /// 根据字段类型获取映射 /// - /// + /// /// - public abstract Dictionary GetMappings(Type fieldType); + public abstract Dictionary GetMappings(PropertyInfo propertyInfo); } } From 561d091b2ca4c8da4546573b3eb82aa03af365bc Mon Sep 17 00:00:00 2001 From: netty2019 <47128297+netty2019@users.noreply.github.com> Date: Sat, 30 Dec 2023 14:51:39 +0800 Subject: [PATCH 04/11] Update Extension.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加valueMappings为空判断 --- .../Extension/Extension.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Magicodes.ExporterAndImporter.Core/Extension/Extension.cs b/src/Magicodes.ExporterAndImporter.Core/Extension/Extension.cs index 2ea2482e..3180bc89 100644 --- a/src/Magicodes.ExporterAndImporter.Core/Extension/Extension.cs +++ b/src/Magicodes.ExporterAndImporter.Core/Extension/Extension.cs @@ -324,11 +324,14 @@ public static void ValueMapping(this PropertyInfo propertyInfo, ref Dictionary(true).FirstOrDefault()?.GetMappings(propertyInfo); - foreach (var valueMapping in valueMappings) + if(valueMappings != null ) { - if (!directory.ContainsKey(valueMapping.Key)) directory.Add(valueMapping.Key, valueMapping.Value); + foreach (var valueMapping in valueMappings) + { + if (!directory.ContainsKey(valueMapping.Key)) directory.Add(valueMapping.Key, valueMapping.Value); + } + if (valueMappings.Count > 0) return; } - if (valueMappings != null && valueMappings.Count > 0) return; //ValueMappingAttribute var mappings = propertyInfo.GetAttributes().ToList(); @@ -371,4 +374,4 @@ public static void ValueMapping(this PropertyInfo propertyInfo, ref Dictionary Date: Sat, 30 Dec 2023 22:22:24 +0800 Subject: [PATCH 05/11] =?UTF-8?q?CsvImporter=E5=A2=9E=E5=8A=A0=E5=AF=BC?= =?UTF-8?q?=E5=85=A5Stream=E6=97=B6=E7=9A=84=E5=9B=9E=E8=B0=83=E5=A7=94?= =?UTF-8?q?=E6=89=98=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ValueMappingsBaseAttribute.cs | 2 +- src/Magicodes.ExporterAndImporter.Csv/CsvImporter.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs b/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs index f01298a7..9c1153c8 100644 --- a/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs +++ b/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs @@ -12,7 +12,7 @@ namespace Magicodes.IE.Core public abstract class ValueMappingsBaseAttribute : Attribute { /// - /// 根据字段类型获取映射 + /// 根据字段信息获取映射 /// /// /// diff --git a/src/Magicodes.ExporterAndImporter.Csv/CsvImporter.cs b/src/Magicodes.ExporterAndImporter.Csv/CsvImporter.cs index 22ce7bb2..cc8c5834 100644 --- a/src/Magicodes.ExporterAndImporter.Csv/CsvImporter.cs +++ b/src/Magicodes.ExporterAndImporter.Csv/CsvImporter.cs @@ -89,7 +89,7 @@ public class CsvImporter : ICsvImporter /// /// /// - public Task> Import(Stream stream, Stream labelingFileStream) where T : class, new() + public Task> Import(Stream stream, Stream labelingFileStream, Func, ImportResult> importResultCallback = null) where T : class, new() { using (var importer = new ImportHelper(stream)) { From ba1237f92cbb19243c4dcfae327b971c422ce277 Mon Sep 17 00:00:00 2001 From: netty <1025556487@qq.com> Date: Sat, 30 Dec 2023 22:31:27 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E7=BC=96=E8=AF=91?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ValueMappingsBaseAttribute.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs b/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs index 9c1153c8..8e00a47f 100644 --- a/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs +++ b/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs @@ -16,6 +16,6 @@ public abstract class ValueMappingsBaseAttribute : Attribute /// /// /// - public abstract Dictionary GetMappings(PropertyInfo propertyInfo); + public abstract Dictionary GetMappings(PropertyInfo propertyInfo); } } From a0cc010f1aea281baa38ec41ca2c56e304f4f96d Mon Sep 17 00:00:00 2001 From: netty <1025556487@qq.com> Date: Tue, 2 Jan 2024 17:06:24 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ValueMappingsBaseAttribute.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs b/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs index 8e00a47f..92943493 100644 --- a/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs +++ b/src/Magicodes.ExporterAndImporter.Core/ValueMappingsBaseAttribute.cs @@ -8,7 +8,6 @@ namespace Magicodes.IE.Core /// /// 值映射 /// - [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] public abstract class ValueMappingsBaseAttribute : Attribute { /// From 2fdb009f41dd2dc31becc4cd3d9f6288f15f7d30 Mon Sep 17 00:00:00 2001 From: netty <1025556487@qq.com> Date: Wed, 3 Jan 2024 08:23:39 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Import/ImportWithOnlyErrorRowsDto.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Magicodes.ExporterAndImporter.Tests/Models/Import/ImportWithOnlyErrorRowsDto.cs b/src/Magicodes.ExporterAndImporter.Tests/Models/Import/ImportWithOnlyErrorRowsDto.cs index 268849af..a2282956 100644 --- a/src/Magicodes.ExporterAndImporter.Tests/Models/Import/ImportWithOnlyErrorRowsDto.cs +++ b/src/Magicodes.ExporterAndImporter.Tests/Models/Import/ImportWithOnlyErrorRowsDto.cs @@ -39,7 +39,7 @@ public class ImportWithOnlyErrorRowsDto /// [ImporterHeader(Name = "身份证号", IsAllowRepeat = false)] [Required(ErrorMessage = "身份证号不能为空")] - [MaxLength(18, ErrorMessage = "身份证字数超出最大限制,请修改!")] + [MaxLength(18, ErrorMessage = "身份证号字数超出最大限制,请修改!")] public string IdCard { get; set; } /// From 4d010e8d9cab0654168ac4a4ea169eea18807f73 Mon Sep 17 00:00:00 2001 From: netty <1025556487@qq.com> Date: Wed, 3 Jan 2024 08:39:32 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Export/ExporterHeaderFilterTestData.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Magicodes.ExporterAndImporter.Tests/Models/Export/ExporterHeaderFilterTestData.cs b/src/Magicodes.ExporterAndImporter.Tests/Models/Export/ExporterHeaderFilterTestData.cs index 09ded2bd..afaca293 100644 --- a/src/Magicodes.ExporterAndImporter.Tests/Models/Export/ExporterHeaderFilterTestData.cs +++ b/src/Magicodes.ExporterAndImporter.Tests/Models/Export/ExporterHeaderFilterTestData.cs @@ -59,7 +59,8 @@ public class ExporterHeaderFilterTestData1 [ExporterHeader(DisplayName = "加粗文本", IsBold = true)] public string Text { get; set; } - [ExporterHeader(DisplayName = "普通文本")] public string Text2 { get; set; } + [ExporterHeader(DisplayName = "普通文本")] + public string Text2 { get; set; } [ExporterHeader(DisplayName = "忽略", IsIgnore = true)] public string Text3 { get; set; } From 00bb7c684df2ad9a7f45e2246bdc4d7412da5614 Mon Sep 17 00:00:00 2001 From: netty <1025556487@qq.com> Date: Wed, 3 Jan 2024 14:10:05 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=92=8C=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.zh-CN.md | 25 +++++++++ .../ExcelExporterWithXSSFWorkbook_Tests.cs | 51 ++++++++++++++++++- .../ExcelExporter_Tests.cs | 49 ++++++++++++++++++ .../Models/Export/Issue544.cs | 49 ++++++++++++++++++ 4 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 src/Magicodes.ExporterAndImporter.Tests/Models/Export/Issue544.cs diff --git a/README.zh-CN.md b/README.zh-CN.md index c5e4d4c4..825bf258 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -228,6 +228,31 @@ public Genders Gender { get; set; } ``` +- **也可以继承“ValueMappingsBaseAttribute”特性基类实现值映射关系,目前仅可用于枚举和Bool类型,支持导入导出。** +```csharp + [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] + public class GenderLocalAttribute : ValueMappingsBaseAttribute + { + public override Dictionary GetMappings(PropertyInfo propertyInfo) + { + var res= new Dictionary(); + res.Add("男",Genders.Male); + res.Add("女",Genders.Female); + return res; + } + } + + + /// + /// 性别 + /// + [ImporterHeader(Name = "性别")] + [Required(ErrorMessage = "性别不能为空")] + [GenderLocal] + public Genders Gender { get; set; } +``` + + - **支持枚举和Bool类型的导入数据验证项的生成,以及相关数据转换** - **枚举默认情况下会自动获取枚举的描述、显示名、名称和值生成数据项** diff --git a/src/Magicodes.ExporterAndImporter.Tests/ExcelExporterWithXSSFWorkbook_Tests.cs b/src/Magicodes.ExporterAndImporter.Tests/ExcelExporterWithXSSFWorkbook_Tests.cs index 805b73e4..c8254c9b 100644 --- a/src/Magicodes.ExporterAndImporter.Tests/ExcelExporterWithXSSFWorkbook_Tests.cs +++ b/src/Magicodes.ExporterAndImporter.Tests/ExcelExporterWithXSSFWorkbook_Tests.cs @@ -958,8 +958,55 @@ public async Task ValueMapping_Test() } } - - + [Fact(DisplayName = "ValueMappingsBase测试#544")] + public async Task ValueMappingsBase_Test() + { + IExporter exporter = new ExcelExporter(); + var filePath = GetTestFilePath($"{nameof(ValueMappingsBase_Test)}.xlsx"); + DeleteFile(filePath); + var list = new List() + { + new Issue544() + { + Gender ="男", + IsAlumni = true, + Name ="张三", + IsAlumni2 = true, + }, + new Issue544() + { + Gender ="男", + IsAlumni = false, + Name ="张三", + IsAlumni2 = true, + }, + new Issue544() + { + Gender ="男", + IsAlumni = null, + Name ="张三", + IsAlumni2 = false, + }, + }; + var result = await exporter.ExportWithXSSFWorkbook(filePath, list); + result.ShouldNotBeNull(); + File.Exists(filePath).ShouldBeTrue(); + using (var pck = new ExcelPackage(new FileInfo(filePath))) + { + pck.Workbook.Worksheets.Count.ShouldBe(1); + var sheet = pck.Workbook.Worksheets.First(); + sheet.Cells["D2"].Text.ShouldBe("是"); + sheet.Cells["D3"].Text.ShouldBe("是"); + sheet.Cells["D4"].Text.ShouldBe("否"); + + sheet.Cells["C2"].Text.ShouldBe("是"); + sheet.Cells["C3"].Text.ShouldBe("否"); + sheet.Cells["C4"].Text.ShouldBe(""); + } + } + + + [Fact(DisplayName = "导出日期格式化#331")] public async Task DateTimeExport_Test() { diff --git a/src/Magicodes.ExporterAndImporter.Tests/ExcelExporter_Tests.cs b/src/Magicodes.ExporterAndImporter.Tests/ExcelExporter_Tests.cs index e1655a8e..d80da49e 100644 --- a/src/Magicodes.ExporterAndImporter.Tests/ExcelExporter_Tests.cs +++ b/src/Magicodes.ExporterAndImporter.Tests/ExcelExporter_Tests.cs @@ -964,6 +964,55 @@ public async Task ValueMapping_Test() } + [Fact(DisplayName = "ValueMappingsBase测试#544")] + public async Task ValueMappingsBase_Test() + { + IExporter exporter = new ExcelExporter(); + var filePath = GetTestFilePath($"{nameof(ValueMappingsBase_Test)}.xlsx"); + DeleteFile(filePath); + var list = new List() + { + new Issue544() + { + Gender ="男", + IsAlumni = true, + Name ="张三", + IsAlumni2 = true, + }, + new Issue544() + { + Gender ="男", + IsAlumni = false, + Name ="张三", + IsAlumni2 = true, + }, + new Issue544() + { + Gender ="男", + IsAlumni = null, + Name ="张三", + IsAlumni2 = false, + }, + }; + var result = await exporter.Export(filePath, list); + result.ShouldNotBeNull(); + File.Exists(filePath).ShouldBeTrue(); + using (var pck = new ExcelPackage(new FileInfo(filePath))) + { + pck.Workbook.Worksheets.Count.ShouldBe(1); + var sheet = pck.Workbook.Worksheets.First(); + sheet.Cells["D2"].Text.ShouldBe("是"); + sheet.Cells["D3"].Text.ShouldBe("是"); + sheet.Cells["D4"].Text.ShouldBe("否"); + + sheet.Cells["C2"].Text.ShouldBe("是"); + sheet.Cells["C3"].Text.ShouldBe("否"); + sheet.Cells["C4"].Text.ShouldBe(""); + } + } + + + [Fact(DisplayName = "导出日期格式化#331")] public async Task DateTimeExport_Test() diff --git a/src/Magicodes.ExporterAndImporter.Tests/Models/Export/Issue544.cs b/src/Magicodes.ExporterAndImporter.Tests/Models/Export/Issue544.cs new file mode 100644 index 00000000..bf3603cb --- /dev/null +++ b/src/Magicodes.ExporterAndImporter.Tests/Models/Export/Issue544.cs @@ -0,0 +1,49 @@ +using Magicodes.ExporterAndImporter.Core; +using Magicodes.ExporterAndImporter.Excel; +using Magicodes.IE.Core; +using System; +using System.Collections.Generic; +using System.Reflection; + +namespace Magicodes.ExporterAndImporter.Tests.Models.Export +{ + [ExcelExporter(Name = "导出结果", TableStyle = OfficeOpenXml.Table.TableStyles.None)] + public class Issue544 + { + /// + /// 名称 + /// + [ExporterHeader(DisplayName = "姓名")] + public string Name { get; set; } + + /// + /// 性别 + /// + [ExporterHeader(DisplayName = "性别")] + public string Gender { get; set; } + + /// + /// 是否校友 + /// + [ExporterHeader(DisplayName = "是否校友")] + [BoolLocal337] + public bool? IsAlumni { get; set; } + + [ExporterHeader(DisplayName = "是否校友2")] + [BoolLocal337] + public bool IsAlumni2 { get; set; } + } + + + [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] + public class BoolLocal337Attribute : ValueMappingsBaseAttribute + { + public override Dictionary GetMappings(PropertyInfo propertyInfo) + { + var res= new Dictionary(); + res.Add("是",true); + res.Add("否",false); + return res; + } + } +} From d506daff75ea5dbba81b6ba05daf378f47c0a981 Mon Sep 17 00:00:00 2001 From: netty <1025556487@qq.com> Date: Wed, 3 Jan 2024 14:13:09 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.zh-CN.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.zh-CN.md b/README.zh-CN.md index 825bf258..0ee706f4 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -236,8 +236,8 @@ public override Dictionary GetMappings(PropertyInfo propertyInfo) { var res= new Dictionary(); - res.Add("男",Genders.Male); - res.Add("女",Genders.Female); + res.Add("男",0); + res.Add("女",1); return res; } }