• [C#] Epplus LoadFromCollection 按照指定格式导出Excel


    Epplus中利用对象集合来生成Excel内容,共有四种方式:

    public ExcelRangeBase LoadFromCollection<T>(IEnumerable<T> Collection);
    public ExcelRangeBase LoadFromCollection<T>(IEnumerable<T> Collection, bool PrintHeaders);
    public ExcelRangeBase LoadFromCollection<T>(IEnumerable<T> Collection, bool PrintHeaders, TableStyles TableStyle);
    public ExcelRangeBase LoadFromCollection<T>(IEnumerable<T> Collection, bool PrintHeaders, TableStyles TableStyle, BindingFlags memberFlags, MemberInfo[] Members);
    LoadFromCollection 默认是在Excel中生成对象中所有的属性的数据。

    当想只生成对象中部分属性的内容,需要调用 LoadFromCollection<T>(IEnumerable<T> Collection, bool PrintHeaders, TableStyles TableStyle, BindingFlags memberFlags, MemberInfo[] Members)
    1 Type typeFromHandle = typeof(TargetObj); //TargetObj 是 IEnumerable中T的类型
    2 MemberInfo[] properties = typeFromHandle.GetProperties(memberFlags);
    3 //过滤出需要导出Excel中的属性
    4 var members = properties.FindAll(filterFunction);
    5 workSheet.Cells.LoadFromCollection(collections, true, OfficeOpenXml.Table.TableStyles.None, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public, members)




  • 相关阅读:
    弱网测试(分析篇)
    弱网测试(资料罗列篇)
    2018年上半年系统分析师上午试题答案
    2018年上半年系统分析师案例分析答案
    测试执行过程注意事项
    略看操作系统
    Activity生命周期
    Android中的数据存储
    Android 进程生命周期 Process Lifecycle
    Android学习链接大放送
  • 原文地址:https://www.cnblogs.com/taofengfeng/p/16419975.html
Copyright © 2020-2023  润新知