网上C#导出Excel的方法有很多。但用来用去感觉不够自动化。于是花了点时间,利用特性做了个比较通用的导出方法。只需要根据实体类,自动导出想要的数据

 

 1.在NuGet上安装Aspose.Cells或者用微软自带类库也可以

 2.需要导出的数据的实例类:

 using System.ComponentModel;
    using System.Reflection;
    using System.Runtime.Serialization;
    public class OrderReport
    {
        [DisplayName("订单编号")]
        public string orderNo { get; set; }

        [IgnoreDataMember]
        public DateTime orderTime { get; set; }
        [DisplayName("订单时间")]
        public String orderTime_fomart { get { return orderTime.ToShortDateString(); } }

        [DisplayName("商品编码")]
        public string itemCode { get; set; }

        [DisplayName("商品名称")]
        public string itemName { get; set; }
    }
View Code

相关文章:

  • 2022-12-23
  • 2022-02-06
  • 2022-12-23
  • 2022-12-23
  • 2021-05-19
  • 2021-06-05
  • 2022-01-02
猜你喜欢
  • 2021-07-25
  • 2021-08-22
  • 2021-07-22
  • 2022-12-23
  • 2021-11-21
  • 2021-08-03
相关资源
相似解决方案