[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

hanzhaoxin/ExcelReport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

快速入门

ExcelReport是什么?

ExcelReport是一个Excel模板渲染引擎。 它基于关注点分离的理念,将数据与表格样式、字体格式分离。
其中模板承载的表格样式、字体格式在可视化的情况下编辑。开发人员只需要绑定数据与目标标签的对应关系。ExcelReport就可以以数据驱动的方式渲染出目标报表。

模块组成

image.png
ExcelReport家族现在有四个成员。
ExcelReport负责报表的渲染逻辑。ExcelReport.Driver为ExcelReport提供了操作Excel文档的抽象接口。
ExcelReport.Driver.NPOI是使用NPOI对ExcelReport.Driver的实现。支持xls、xlsx两种格式的Excel文档。ExcelReport.Driver.CSV是针对csv格式的Excel文档对ExcelReport.Driver的实现。

渲染模型

image.png
Template:模板承载的表格样式、字体格式、占位标签等。
Render:指定模板标签与数据的关系。
Data:注入模板的数据。整个渲染过程也是数据驱动渲染的。
Output:输出文件

入门示例

  • 步骤一:新建入门项目QuickStart,并引入nuget包:

image.png
image.png

  • 步骤二:创建并编辑模板

image.png
image.png

  • 步骤三:编写代码
internal class Program
{

       private static void Main(string[] args)
       {
           // 项目启动时,添加
           Configurator.Put(".xlsx", new WorkbookLoader());

           var num = 1;
           ExportHelper.ExportToLocal(@"templates\student.xlsx", "out.xlsx",
                   new SheetRenderer("Students",
                       new RepeaterRenderer<StudentInfo>("Roster", StudentLogic.GetList(),
                           new ParameterRenderer<StudentInfo>("No", t => num++),
                           new ParameterRenderer<StudentInfo>("Name", t => t.Name),
                           new ParameterRenderer<StudentInfo>("Gender", t => t.Gender ? "" : ""),
                           new ParameterRenderer<StudentInfo>("Class", t => t.Class),
                           new ParameterRenderer<StudentInfo>("RecordNo", t => t.RecordNo),
                           new ParameterRenderer<StudentInfo>("Phone", t => t.Phone),
                           new ParameterRenderer<StudentInfo>("Email", t => t.Email)
                           ),
                        new ParameterRenderer("Author", "hzx")
                       )
                   );
           Console.WriteLine("finished!");
           Console.ReadKey();
       }
}
public class StudentInfo
{
       public string Name { get; set; }
       public bool Gender { get; set; }
       public string Class { get; set; }
       public string RecordNo { get; set; }
       public string Phone { get; set; }
       public string Email { get; set; }
}
public static class StudentLogic
{
       public static List<StudentInfo> GetList()
       {
           List<StudentInfo> list = new List<StudentInfo>();
           list.Add(new StudentInfo() { Class = "一班", Name = "XXX01", Gender = true, RecordNo = "YYY0001", Phone = "158******01", Email = "xxx01@live.cn" });
           list.Add(new StudentInfo() { Class = "二班", Name = "XXX02", Gender = false, RecordNo = "YYY0002", Phone = "158******02", Email = "xxx02@live.cn" });
           list.Add(new StudentInfo() { Class = "一班", Name = "XXX03", Gender = true, RecordNo = "YYY0003", Phone = "158******03", Email = "xxx03@live.cn" });
           list.Add(new StudentInfo() { Class = "一班", Name = "XXX04", Gender = true, RecordNo = "YYY0004", Phone = "158******04", Email = "xxx04@live.cn" });
           return list;
       }
}
  • 输出结果 image.png

更多文章

ExcelReport文档

相关用户组

npoi users group

About

This reporting engine is built on NPOI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages