예제 #1
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDlg = new SaveFileDialog();
            saveFileDlg.Filter = "Excel 2003文件|*.xls|Excel 2007文件|*.xlsx";

            if (DialogResult.OK.Equals(saveFileDlg.ShowDialog()))
            {

                ParameterCollection collection = new ParameterCollection();
                collection.Load(@"Template\Template.xml");
                int num = 0;
                List<ElementFormatter> formatters = new List<ElementFormatter>();
                formatters.Add(new RepeaterFormatter<StudentInfo>(collection["Sheet1", "rptStudentInfo_Start"],collection["Sheet1", "rptStudentInfo_End"], StudentLogic.GetList(),
                    new RepeaterCellInfo<StudentInfo>(collection["Sheet1", "Name"], t => t.Name),
                    new RepeaterCellInfo<StudentInfo>(collection["Sheet1", "Gender"], t => t.Gender ? "男" : "女"),
                    new RepeaterCellInfo<StudentInfo>(collection["Sheet1", "Class"], t => t.Class),
                    new RepeaterCellInfo<StudentInfo>(collection["Sheet1", "RecordNo"], t => t.RecordNo),
                    new RepeaterCellInfo<StudentInfo>(collection["Sheet1", "Phone"], t => t.Phone),
                    new RepeaterCellInfo<StudentInfo>(collection["Sheet1", "Email"], t => t.Email)
                    ));

                //导出文件到本地
                ExportHelper.ExportToLocal(@"Template\Template.xls", saveFileDlg.FileName,
                    new SheetFormatterContainer("Sheet1", formatters)
                    );

            }
        }
예제 #2
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDlg = new SaveFileDialog();
            saveFileDlg.Filter = "Excel 2003文件|*.xls|Excel 2007文件|*.xlsx";

            if (DialogResult.OK.Equals(saveFileDlg.ShowDialog()))
            {

                ParameterCollection collection = new ParameterCollection();
                collection.Load(@"Template\Template.xml");

                List<ElementFormatter> sheet1Formatters = new List<ElementFormatter>();
                sheet1Formatters.Add(new PartFormatter(collection["Sheet1", "Parameter"], "Parameter","World"));

                List<ElementFormatter> sheet2Formatters = new List<ElementFormatter>();
                sheet2Formatters.Add(new PartFormatter(collection["Sheet2", "Parameter"], "Parameter", "ExcelReport"));

                //导出文件到本地
                ExportHelper.ExportToLocal(@"Template\Template.xls", saveFileDlg.FileName,
                    new SheetFormatterContainer("Sheet1", sheet1Formatters),
                    new SheetFormatterContainer("Sheet2", sheet2Formatters)
                    );

            }
        }
예제 #3
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDlg = new SaveFileDialog();
            saveFileDlg.Filter = "Excel 2003文件|*.xls|Excel 2007文件|*.xlsx";

            if (DialogResult.OK.Equals(saveFileDlg.ShowDialog()))
            {

                ParameterCollection collection = new ParameterCollection();
                collection.Load(@"Template\Template.xml");

                List<ElementFormatter> formatters = new List<ElementFormatter>();
                formatters.Add(new CellFormatter(collection["Sheet1","String"],"Hello World!"));
                formatters.Add(new CellFormatter(collection["Sheet1", "DateTime"], DateTime.Now));
                formatters.Add(new CellFormatter(collection["Sheet1", "Boolean"], true));
                formatters.Add(new CellFormatter(collection["Sheet1", "Double"], 3.14));
                formatters.Add(new CellFormatter(collection["Sheet1", "Image"], Image.FromFile("Image/C#高级编程.jpg").ToBuffer()));

                //导出文件到本地
                ExportHelper.ExportToLocal(@"Template\Template.xls", saveFileDlg.FileName,
                    new SheetFormatterContainer("Sheet1", formatters)
                    );

            }
        }
예제 #4
0
        protected void btnExport_Click(object sender, EventArgs e)
        {
            ExcelReport.ParameterCollection collection = new ExcelReport.ParameterCollection();
            collection.Load(Server.MapPath(@"Template\Template.xml"));

            List <ElementFormatter> formatters = new List <ElementFormatter>();

            formatters.Add(new CellFormatter(collection["GradeDetail", "Dept"], "某某学院"));
            formatters.Add(new CellFormatter(collection["GradeDetail", "Class"], "某某班级"));
            formatters.Add(new CellFormatter(collection["GradeDetail", "StudNo"], "2009*****"));
            formatters.Add(new CellFormatter(collection["GradeDetail", "StudName"], "韩兆新"));
            formatters.Add(new CellFormatter(collection["GradeDetail", "ExportDate"], DateTime.Now));

            List <GradeInfo> gradeInfoList = new List <GradeInfo>();

            gradeInfoList.Add(new GradeInfo()
            {
                CGPA = 18, CourseID = "KC-0001", CourseName = "高等数学", CourseType = "理论课", Credit = 6, EvaluationMode = "考试", GainCredit = 6, GPA = 3, Grade = 86, StudyNature = "初修", Type = "必修课"
            });
            gradeInfoList.Add(new GradeInfo()
            {
                CGPA = 2, CourseID = "KC-0002", CourseName = "计算机应用基础", CourseType = "理论课", Credit = 2, EvaluationMode = "考试", GainCredit = 2, GPA = 1, Grade = 93, StudyNature = "初修", Type = "必修课"
            });
            gradeInfoList.Add(new GradeInfo()
            {
                CGPA = 9, CourseID = "KC-0003", CourseName = "C程序设计", CourseType = "理论课", Credit = 3, EvaluationMode = "考试", GainCredit = 3, GPA = 3, Grade = 97, StudyNature = "初修", Type = "必修课", Remark = "备注信息"
            });

            formatters.Add(new TableFormatter <GradeInfo>(collection["GradeDetail", "CourseID"].X, gradeInfoList,
                                                          new TableColumnInfo <GradeInfo>(collection["GradeDetail", "CGPA"].Y, t => t.CGPA),
                                                          new TableColumnInfo <GradeInfo>(collection["GradeDetail", "CourseID"].Y, t => t.CourseID),
                                                          new TableColumnInfo <GradeInfo>(collection["GradeDetail", "CourseName"].Y, t => t.CourseName),
                                                          new TableColumnInfo <GradeInfo>(collection["GradeDetail", "CourseType"].Y, t => t.CourseType),
                                                          new TableColumnInfo <GradeInfo>(collection["GradeDetail", "Credit"].Y, t => t.Credit),
                                                          new TableColumnInfo <GradeInfo>(collection["GradeDetail", "EvaluationMode"].Y, t => t.EvaluationMode),
                                                          new TableColumnInfo <GradeInfo>(collection["GradeDetail", "GainCredit"].Y, t => t.GainCredit),
                                                          new TableColumnInfo <GradeInfo>(collection["GradeDetail", "GPA"].Y, t => t.GPA),
                                                          new TableColumnInfo <GradeInfo>(collection["GradeDetail", "Grade"].Y, t => t.Grade),
                                                          new TableColumnInfo <GradeInfo>(collection["GradeDetail", "Remark"].Y, t => t.Remark),
                                                          new TableColumnInfo <GradeInfo>(collection["GradeDetail", "StudyNature"].Y, t => t.StudyNature),
                                                          new TableColumnInfo <GradeInfo>(collection["GradeDetail", "Type"].Y, t => t.Type)
                                                          ));
            Export.ExportToWeb(Server.MapPath(@"Template\Template.xls"), "GradeDetail",
                               new SheetFormatterContainer("GradeDetail", formatters));
        }
예제 #5
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDlg = new SaveFileDialog();
            saveFileDlg.Filter = "Excel 2003文件|*.xls|Excel 2007文件|*.xlsx";

            if (DialogResult.OK.Equals(saveFileDlg.ShowDialog()))
            {

                ParameterCollection collection = new ParameterCollection();
                collection.Load(@"Template\Template.xml");

                List<ElementFormatter> formatters = new List<ElementFormatter>();
                formatters.Add(new PartFormatter(collection["局部格式化器", "UserName"], "UserName", "Jensen"));
                formatters.Add(new PartFormatter(collection["局部格式化器", "GroupNo"], "GroupNo", "116476496"));

                //导出文件到本地
                ExportHelper.ExportToLocal(@"Template\Template.xls", saveFileDlg.FileName,
                    new SheetFormatterContainer("局部格式化器", formatters)
                    );

            }
        }
예제 #6
0
 public static ParameterCollection Parse(string templatePath)
 {
     ParameterCollection workbookParameter = new ParameterCollection();
     IWorkbook workbook = NPOIHelper.LoadWorkbook(templatePath);
     foreach (ISheet sheet in workbook)
     {
         foreach (IRow row in sheet)
         {
             foreach (ICell cell in row.Cells)
             {
                 if (cell.CellType.Equals(CellType.String))
                 {
                     string cellText = cell.StringCellValue;
                     MatchCollection matches = new Regex(@"(?<=\$\[)([\w]*)(?=\])").Matches(cellText);
                     foreach (Match match in matches)
                     {
                         workbookParameter[sheet.SheetName, match.Value] = new Point(cell.RowIndex, cell.ColumnIndex);
                     }
                 }
             }
         }
     }
     return workbookParameter;
 }
예제 #7
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDlg = new SaveFileDialog();
            saveFileDlg.Filter = "Excel 2003文件|*.xls|Excel 2007文件|*.xlsx";

            if (DialogResult.OK.Equals(saveFileDlg.ShowDialog()))
            {
                ParameterCollection collection = new ParameterCollection();
                collection.Load(@"Template\演示:工资条模板.xml");

                List<ElementFormatter> payTableFormatters = new List<ElementFormatter>();
                payTableFormatters.Add(new PartFormatter(collection["工资表", "Dept"], "Dept", "生产A部"));
                payTableFormatters.Add(new CellFormatter(collection["工资表", "Month"], "2015年4月"));
                payTableFormatters.Add(new TableFormatter<SalaryInfo>(collection["工资表", "JobNo"].X, SalaryInfoLogic.GetList(),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "JobNo"].Y, t => t.JobNo),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "Name"].Y, t => t.Name),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "HourlyWage"].Y, t => t.HourlyWage),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "ManHour"].Y, t => t.ManHour),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "UsualOvertime"].Y, t => t.UsualOvertime),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "WeekendOvertime"].Y, t => t.WeekendOvertime),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "LegalOvertime"].Y, t => t.LegalOvertime),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "BasePay"].Y, t => t.BasePay),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "OvertimePay"].Y, t => t.OvertimePay),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "FoodAllowance"].Y, t => t.FoodAllowance),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "OtherAllowance"].Y, t => t.OtherAllowance),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "GrossPay"].Y, t => t.GrossPay),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "BoardWages"].Y, t => t.BoardWages),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "Utilities"].Y, t => t.Utilities),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "BadDebt"].Y, t => t.BadDebt),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "RealWages"].Y, t => t.RealWages),
                    new TableColumnInfo<SalaryInfo>(collection["工资表", "Remark"].Y, t => t.Remark)
                    ));

                List<ElementFormatter> payStripFormatters = new List<ElementFormatter>();
                payStripFormatters.Add(new RepeaterFormatter<SalaryInfo>(collection["工资条", "rptPaySlipStart"], collection["工资条", "rptPaySlipEnd"], SalaryInfoLogic.GetList(),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "Title"], t => "某工厂生产A部工资条"),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "Month"], t => "2015年4月"),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "JobNo"], t => t.JobNo),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "Name"], t => t.Name),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "HourlyWage"], t => t.HourlyWage),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "ManHour"], t => t.ManHour),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "UsualOvertime"], t => t.UsualOvertime),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "WeekendOvertime"], t => t.WeekendOvertime),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "LegalOvertime"], t => t.LegalOvertime),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "BasePay"], t => t.BasePay),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "OvertimePay"], t => t.OvertimePay),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "FoodAllowance"], t => t.FoodAllowance),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "OtherAllowance"], t => t.OtherAllowance),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "GrossPay"], t => t.GrossPay),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "BoardWages"], t => t.BoardWages),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "Utilities"], t => t.Utilities),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "BadDebt"], t => t.BadDebt),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "RealWages"], t => t.RealWages),
                    new RepeaterCellInfo<SalaryInfo>(collection["工资条", "Remark"], t => t.Remark)
                    ));

                //导出文件到本地
                ExportHelper.ExportToLocal(@"Template\演示:工资条模板.xlsx", saveFileDlg.FileName,
                    new SheetFormatterContainer("工资表", payTableFormatters),
                    new SheetFormatterContainer("工资条", payStripFormatters)
                    );
            }
        }