示例#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)
        {
            var saveFileDlg = new SaveFileDialog {
                Filter = Resources.SaveFileFilter
            };

            if (DialogResult.OK.Equals(saveFileDlg.ShowDialog()))
            {
                var workbookParameterContainer = new WorkbookParameterContainer();
                workbookParameterContainer.Load(@"Template\Template.xml");
                SheetParameterContainer sheetParameterContainer = workbookParameterContainer["重复单元格式化器"];

                ExportHelper.ExportToLocal(@"Template\Template.xls", saveFileDlg.FileName,
                                           new SheetFormatter("重复单元格式化器",
                                                              new RepeaterFormatter <StudentInfo>(sheetParameterContainer["rptStudentInfo_Start"],
                                                                                                  sheetParameterContainer["rptStudentInfo_End"], StudentLogic.GetList(),
                                                                                                  new CellFormatter <StudentInfo>(sheetParameterContainer["Name"], t => t.Name),
                                                                                                  new CellFormatter <StudentInfo>(sheetParameterContainer["Gender"], t => t.Gender ? "男" : "女"),
                                                                                                  new CellFormatter <StudentInfo>(sheetParameterContainer["Class"], t => t.Class),
                                                                                                  new CellFormatter <StudentInfo>(sheetParameterContainer["RecordNo"], t => t.RecordNo),
                                                                                                  new CellFormatter <StudentInfo>(sheetParameterContainer["Phone"], t => t.Phone),
                                                                                                  new CellFormatter <StudentInfo>(sheetParameterContainer["Email"], t => t.Email)
                                                                                                  )
                                                              )
                                           );
            }
        }