public ActionResult DownLoadYearlyTaskTemplete(int task_type) { //模板名称 string templeteName = "全年任务指标"; //模板各列名称 string[] listColumn = new string[] { }; if (task_type == 0) { listColumn = Constant.YearlyTaskTempleteCompanyListColumn; } else { listColumn = Constant.YearlyTaskTempletePersonListColumn; } //指定excel格式 ExcelConfig excelconfig = new ExcelConfig(); excelconfig.Title = Server.UrlDecode(templeteName); excelconfig.TitleFont = "微软雅黑"; excelconfig.TitlePoint = 15; excelconfig.FileName = Server.UrlDecode(templeteName) + "数据录入模板.xls"; excelconfig.IsAllSizeColumn = true; excelconfig.ColumnEntity = new List <ColumnEntity>(); //行数据 DataTable rowData = new DataTable(); //各个细项指标 for (int i = 0; i < listColumn.Length; i++) { string columnName = "YearlyTask_" + i; string excelColumnName = listColumn[i]; excelconfig.ColumnEntity.Add(new ColumnEntity() { Column = columnName, ExcelColumn = excelColumnName, Alignment = "center" }); rowData.Columns.Add(columnName); } if (task_type == 0) { //获取所有子公司 OrganizeEntity org = organizeApp.GetForm(BlocId); if (org == null) { return(Error("配置文件中的总公司id不存在,无法生产下载模板!")); } List <OrganizeEntity> branchList = organizeApp.GetListByParentIdOrderById(org.F_Id, CompanyId); DataRow dr = rowData.NewRow(); for (int i = 0; i < branchList.Count; i++) { dr = rowData.NewRow(); dr["YearlyTask_0"] = branchList[i].F_FullName; rowData.Rows.Add(dr); } } else { //获取所有当前公司下客户经理 List <UserEntity> managerList = null; if (OperatorProvider.Provider.GetCurrent() != null) { managerList = userApp.GetByOrgIdAndCMRoleId(OperatorProvider.Provider.GetCurrent().CompanyId, CustomerManagerRoleId); if (managerList.Count == 0) { return(Error("此公司下暂无客户经理,无法生成Excel模板!")); } } else { return(Error("无法获取当前登录人信息!")); } //List<UserEntity> managerList = userApp.GetList(); for (int i = 0; i < managerList.Count; i++) { DataRow dr = rowData.NewRow(); dr = rowData.NewRow(); dr["YearlyTask_0"] = managerList[i].F_RealName; dr["YearlyTask_14"] = managerList[i].F_MobilePhone; rowData.Rows.Add(dr); } } ExcelHelper.ExcelDownload(rowData, excelconfig); return(Success("操作成功。", null)); }