示例(导出学生成绩明细)
步骤一:设计Excel模板
首先,使用Excel软件设计模板(我没有安装MSOffice,用LibreOffice Calc做的演示)。在模板中要填充数据的位置用$[ParameterName]代替。
步骤二:生成模板填充规则文件
使用模板填充规则文件生成工具(ERTool)为步骤一设计的Excel模板生成填充规则文件。
步骤三:为模板填充数据
实现代码(导出到本地):
//实例化一个参数容器,并加载模板填充规则文件
ParameterCollection collection = new ParameterCollection();
(@"Template\");
//实例化一个元素格式化器列表
List<ElementFormatter> formatters = new List<ElementFormatter>();
(new CellFormatter(collection["GradeDetail", "Dept"], "某某学院")); //添加一个单元格格式化器
(new CellFormatter(collection["GradeDetail", "Class"], "某某班级"));
(new CellFormatter(collection["GradeDetail", "StudNo"], "2009*****"));
(new CellFormatter(collection["GradeDetail", "StudName"], "韩兆新"));
(new CellFormatter(collection["GradeDetail", "ExportDate"], ));
List<GradeInfo> gradeInfoList = new List<GradeInfo>();
(new GradeInfo() { CGPA = 18, CourseID = "KC-0001", CourseName = "高等数学", CourseType = "理论课", Credit = 6, EvaluationMode = "考试", GainCredit = 6, GPA = 3, Grade = 86, StudyNature = "初修", Type = "必修课" });
(new GradeInfo() { CGPA = 2, CourseID = "KC-0002", CourseName = "计算机应用基础", CourseType = "理论课", Credit = 2, EvaluationMode = "考试", GainCredit = 2, GPA = 1, Grade = 93, StudyNature = "初修", Type = "必修课" });
(new GradeInfo() { CGPA
使用ExcelReport导出Excel 来自淘豆网m.daumloan.com转载请标明出处.