1. 程式人生 > >.NET 開源匯入匯出庫 Magicodes.IE 2.5釋出

.NET 開源匯入匯出庫 Magicodes.IE 2.5釋出

今天我們釋出了2.5版本,這當然也離不開大家對`Magicodes.IE`的支援,今天我也是跟往常一樣列舉了該版本一些重要的更新內容。 當然也要說一下,在這個版本中我們設計了全新的LOGO ![file](https://blog.stackable.cn/uploads/img-7c871463-411f-4be3-b1aa-b38dae0ae981.png) ## Excel匯出 - Excel匯出支援HeaderRowIndex [#164](https://github.com/dotnetcore/Magicodes.IE/issues/164) 在`ExcelExporterAttribute`匯出特性類中新增`HeaderRowIndex`屬性,方便匯出時去指定從第一行開始匯出。 - 增加Excel列舉匯出對DescriptionAttribute的支援 [#168](https://github.com/dotnetcore/Magicodes.IE/issues/168) 在匯出列舉型別時起初我們可以通過ValueMapping和匯出列舉本身的字串名稱,在現在我們可以通過 [DescriptionAttribute](https://docs.microsoft.com/zh-cn/dotnet/api/system.componentmodel.descriptionattribute?WT.mcid=DT-MVP-5003855)、 [DisplayAttribute](https://docs.microsoft.com/zh-cn/dotnet/api/system.componentmodel.DisplayAttribute?WT.mcid=DT-MVP-5003855), [DisplayNameAttribute](https://docs.microsoft.com/zh-cn/dotnet/api/system.componentmodel.DisplayNameAttribute?WT.mcid=DT-MVP-5003855) 實現Text值匯出 ```csharp enum Sex { /// /// 男 /// [Description("男")] boy = 1, /// /// 女 /// [Description("女")] girl = 2 } ``` - TableStyle修改為列舉型別 在這之前我們將`TableStyle`屬性放在了`ExporterAttribute`基礎特性中,起初我們的TableStyle屬性為字串, 但是帶給了我們不必要的麻煩,很難讓使用者去查詢這些樣式名稱,所以此處我們將其換成了列舉型別,方便使用者從列表中 進行查詢相關樣式 ```csharp [ExcelExporter(Name = "測試", TableStyle = TableStyles.Light10)] ``` ## Excel匯入 - Excel生成匯入模板支援內建資料驗證[#167](https://github.com/dotnetcore/Magicodes.IE/issues/167) 對於內建資料驗證的支援可通過`IsInterValidation`屬性開啟,並且需要注意的是僅 支援[MaxLengthAttribute](https://docs.microsoft.com/zh-cn/dotnet/api/system.componentmodel.dataannotations.maxlengthattribute?WT.mc_id=DT-MVP-5003855&view=net-5.0)、 [MinLengthAttribute](https://docs.microsoft.com/zh-cn/dotnet/api/system.componentmodel.dataannotations.minlengthattribute?WT.mc_id=DT-MVP-5003855)、 [StringLengthAttribute](https://docs.microsoft.com/zh-cn/dotnet/api/system.componentmodel.dataannotations.StringLengthAttribute?WT.mc_id=DT-MVP-5003855&view=net-5.0)、 [RangeAttribute](https://docs.microsoft.com/zh-cn/dotnet/api/system.componentmodel.dataannotations.RangeAttribute?WT.mc_id=DT-MVP-5003855&view=net-5.0) 支援對內建資料驗證的開啟操作。 ![file](https://blog.stackable.cn/uploads/img-ab2a0fc7-ce9c-48f1-b9d9-ce6e68f5d1c2.png) ![file](https://blog.stackable.cn/uploads/img-eb2e85c4-46d3-4640-9451-4947949532bc.png) 支援對輸入提示的展示操作。 ![file](https://blog.stackable.cn/uploads/img-e0def8aa-343a-4dc0-b100-41089b7f4400.png) 示例程式碼如下所示: ```csharp public class GenerateStudentImportSheetDataValidationDto { /// /// 序號 ///
[ImporterHeader(Name = "序號", IsInterValidation = true)] [Range(minimum: 0, maximum: 20, ErrorMessage = "序號最大為20")] public long SerialNumber { get; set; } /// /// 學籍號 /// [ImporterHeader(Name = "學籍號", IsAllowRepeat = false, IsInterValidation = true)] [MaxLength(30, ErrorMessage = "學籍號字數超出最大限制,請修改!")] public string StudentCode { get; set; } /// /// 姓名 ///
[ImporterHeader(Name = "姓名")] [Required(ErrorMessage = "學生姓名不能為空")] [MaxLength(50, ErrorMessage = "名稱字數超出最大限制,請修改!")] public string Name { get; set; } /// /// 年齡 /// [ImporterHeader(Name = "年齡", IsInterValidation = true)] [Range(minimum: 18, maximum: 20, ErrorMessage = "年齡範圍需要在18-20歲哦")] public int Age { get; set; } /// /// MinTest ///
[ImporterHeader(Name = "MinTest", IsInterValidation = true)] [MinLength(5, ErrorMessage = "最小長度為5哦")] public string MinTest { get; set; } /// /// 忽略型別 /// [ImporterHeader(Name = "忽略型別", IsInterValidation = true)] [Range(minimum: 18, maximum: 20, ErrorMessage = "年齡範圍需要在18-20歲哦", ErrorMessageResourceType = typeof(string))] public int IgnoreType { get; set; } [ImporterHeader(Name = "出生日期", IsInterValidation = true, ShowInputMessage = "輸入日期")] [Range(typeof(DateTime), minimum: "2020-10-20", maximum: "2020-10-24", ErrorMessage = "日期範圍超出了哦")] public DateTime Birthday { get; set; } } ``` > 注意:資料範圍驗證僅支援DateTime和int型別 - 匯入對ColumnIndex的支援[#198](https://github.com/dotnetcore/Magicodes.IE/issues/198) 匯入功能支援`ColumnIndex`可以通過去指定某一列資料列,這樣在複雜的列名時結構時,我們也可以直接 輕鬆的應對 ![file](https://blog.stackable.cn/uploads/img-96a6523a-9130-42ec-b71f-c77f9645f23b.png) ```csharp [ImporterHeader(Name = "年齡", ColumnIndex = 3)] public int? Age { get; set; } ``` 歡迎掃碼加入微信群 https://github.com/dotnetcore/Magicodes.IE