Ejemplo n.º 1
0
        /// <summary>
        /// 导出用户列表
        /// </summary>
        /// <returns></returns>
        public void GetExportList()
        {
            //取出数据源
            DataTable exportTable = service.GetExportList();
            //设置导出格式
            ExcelConfig excelconfig = new ExcelConfig();

            excelconfig.Title           = "测试用户导出";
            excelconfig.TitleFont       = "微软雅黑";
            excelconfig.TitlePoint      = 25;
            excelconfig.FileName        = "用户导出.xls";
            excelconfig.IsAllSizeColumn = true;
            //每一列的设置,没有设置的列信息,系统将按datatable中的列名导出
            List <ColumnEntity> listColumnEntity = new List <ColumnEntity>();

            excelconfig.ColumnEntity = listColumnEntity;
            ColumnEntity columnentity = new ColumnEntity();

            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "account", ExcelColumn = "账户"
            });
            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "realname", ExcelColumn = "姓名"
            });
            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "gender", ExcelColumn = "性别"
            });
            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "birthday", ExcelColumn = "生日"
            });
            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "mobile", ExcelColumn = "手机", Background = Color.Red
            });
            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "telephone", ExcelColumn = "电话", Background = Color.Red
            });
            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "wechat", ExcelColumn = "微信"
            });
            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "manager", ExcelColumn = "主管"
            });
            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "organize", ExcelColumn = "公司"
            });
            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "department", ExcelColumn = "部门"
            });
            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "description", ExcelColumn = "说明"
            });
            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "createdate", ExcelColumn = "创建日期"
            });
            excelconfig.ColumnEntity.Add(new ColumnEntity()
            {
                Column = "createusername", ExcelColumn = "创建人"
            });
            //调用导出方法
            ExcelHelper.ExcelDownload(exportTable, excelconfig);
            //从泛型Lis导出
            //TExcelHelper<DepartmentEntity>.ExcelDownload(department.GetList().ToList(), excelconfig);
        }