.NET 开源导入导出库 Magicodes.IE 2.5发布

今天我们发布了2.5版本,这当然也离不开大家对Magicodes.IE的支持,今天我也是跟往常一样列举了该版本一些重要的更新内容。

当然也要说一下,在这个版本中我们设计了全新的LOGO

file

Excel导出

  • Excel导出支持HeaderRowIndex #164

ExcelExporterAttribute导出特性类中添加HeaderRowIndex属性,方便导出时去指定从第一行开始导出。

  • 增加Excel枚举导出对DescriptionAttribute的支持 #168

在导出枚举类型时起初我们可以通过ValueMapping和导出枚举本身的字符串名称,在现在我们可以通过
DescriptionAttribute
DisplayAttribute,
DisplayNameAttribute
实现Text值导出

enum Sex
{
        /// <summary>
        ///
        /// </summary>
        [Description("男")]
        boy = 1,
        /// <summary>
        ///
        /// </summary>
        [Description("女")]
        girl = 2
}
  • TableStyle修改为枚举类型

在这之前我们将TableStyle属性放在了ExporterAttribute基础特性中,起初我们的TableStyle属性为字符串,
但是带给了我们不必要的麻烦,很难让使用者去查找这些样式名称,所以此处我们将其换成了枚举类型,方便使用者从列表中
进行查找相关样式

  [ExcelExporter(Name = "测试", TableStyle = TableStyles.Light10)]

Excel导入

  • Excel生成导入模板支持内置数据验证#167

对于内置数据验证的支持可通过IsInterValidation属性开启,并且需要注意的是仅
支持MaxLengthAttribute
MinLengthAttribute
StringLengthAttribute
RangeAttribute

支持对内置数据验证的开启操作。
file

file

支持对输入提示的展示操作。

file

示例代码如下所示:

    public class GenerateStudentImportSheetDataValidationDto
    {
        /// <summary>
        ///     序号
        /// </summary>
        [ImporterHeader(Name = "序号", IsInterValidation = true)]
        [Range(minimum: 0, maximum: 20, ErrorMessage = "序号最大为20")]
        public long SerialNumber { get; set; }

        /// <summary>
        ///     学籍号
        /// </summary>
        [ImporterHeader(Name = "学籍号", IsAllowRepeat = false, IsInterValidation = true)]
        [MaxLength(30, ErrorMessage = "学籍号字数超出最大限制,请修改!")]
        public string StudentCode { get; set; }

        /// <summary>
        ///     姓名
        /// </summary>
        [ImporterHeader(Name = "姓名")]
        [Required(ErrorMessage = "学生姓名不能为空")]
        [MaxLength(50, ErrorMessage = "名称字数超出最大限制,请修改!")]
        public string Name { get; set; }

        /// <summary>
        ///     年龄
        /// </summary>
        [ImporterHeader(Name = "年龄", IsInterValidation = true)]
        [Range(minimum: 18, maximum: 20, ErrorMessage = "年龄范围需要在18-20岁哦")]
        public int Age { get; set; }

        /// <summary>
        ///     MinTest
        /// </summary>
        [ImporterHeader(Name = "MinTest", IsInterValidation = true)]
        [MinLength(5, ErrorMessage = "最小长度为5哦")]
        public string MinTest { get; set; }

        /// <summary>
        ///     忽略类型
        /// </summary>
        [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

导入功能支持ColumnIndex可以通过去指定某一列数据列,这样在复杂的列名时结构时,我们也可以直接
轻松的应对

file

[ImporterHeader(Name = "年龄", ColumnIndex = 3)]
public int? Age { get; set; }

欢迎扫码加入微信群

https://github.com/dotnetcore/Magicodes.IE

posted @   HueiFeng  阅读(689)  评论(4编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示