public ActionResult ExportFromCfg() { var excelWriter = new ExcelWriter(); Dictionary<string, object> listColumn = new Dictionary<string, object>(); excelWriter.Map("LoginName","登录名"); excelWriter.Map("Name", "姓名"); excelWriter.Map("MobilePhone", "手机号"); excelWriter.Map("Birthday", "生日"); byte[] buffer = excelWriter.Write(OrganizationBusiness.GetUserById(CurrentUser.UserID), new Dictionary<string, ExcelFormatter>() { { "birthday", new ExcelFormatter() { ColumnTrans = EnumColumnTrans.ConvertTime, DropSource = "" } } }); var fileName = "用户信息导入"; if (!Request.ServerVariables["http_user_agent"].ToLower().Contains("firefox")) fileName = HttpUtility.UrlEncode(fileName); this.Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx"); return File(buffer, "application/ms-excel"); }
public ActionResult ExportFromCfg() { var excelWriter = new ExcelWriter(); Dictionary<string, object> listColumn = new Dictionary<string, object>(); excelWriter.Map("Name", "公司名称"); excelWriter.Map("Contcat", "客户名称"); excelWriter.Map("Jobs", "职位"); excelWriter.Map("MobilePhone", "联系电话"); excelWriter.Map("Email", "邮箱"); excelWriter.Map("Province", "省"); excelWriter.Map("City", "市"); excelWriter.Map("District", "区"); excelWriter.Map("Address", "详细地址"); excelWriter.Map("Description", "描述"); byte[] buffer = excelWriter.Write(OrganizationBusiness.GetUserById(CurrentUser.UserID), new Dictionary<string, ExcelFormatter>() { { "birthday", new ExcelFormatter() { ColumnTrans = EnumColumnTrans.ConvertTime, DropSource = "" } } }); var fileName = "客户信息导入"; if (!Request.ServerVariables["http_user_agent"].ToLower().Contains("firefox")) fileName = HttpUtility.UrlEncode(fileName); this.Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx"); return File(buffer, "application/ms-excel"); }
public ActionResult ExportFromCustomer(bool test = false, string model = "", string filleName = "企业客户", string filter="") { Dictionary<string, ExcelFormatter> dic = new Dictionary<string, ExcelFormatter>(); FilterCustomer qicCustomer =new FilterCustomer(); Dictionary<string, ExcelModel> listColumn = new Dictionary<string, ExcelModel>(); if (string.IsNullOrEmpty(filter)) { listColumn = GetColumnForJson("customer", ref dic, model, test ? "testexport" : "export", CurrentUser.ClientID); } else { JavaScriptSerializer serializer = new JavaScriptSerializer(); qicCustomer=serializer.Deserialize<FilterCustomer>(filter); listColumn = GetColumnForJson("customer", ref dic, !string.IsNullOrEmpty(model) ? model : qicCustomer.ExcelType == 0 ? "Item" : "OwnItem", test ? "testexport" : "export", CurrentUser.ClientID); } var excelWriter = new ExcelWriter(); foreach (var key in listColumn) { excelWriter.Map(key.Key, key.Value.Title); } byte[] buffer; DataTable dt = new DataTable(); //模版导出 if (test) { DataRow dr = dt.NewRow(); foreach (var key in listColumn) { DataColumn dc1 = new DataColumn(key.Key, Type.GetType("System.String")); dt.Columns.Add(dc1); if (key.Key == "extent") { dr[key.Key] = "下拉框中选择"; } else if (key.Key == "industryid") { dr[key.Key] = "下拉框中选择"; } else if (key.Key == "province") { dr[key.Key] = "下拉框中选择"; } else { dr[key.Key] = key.Value.DefaultText; } } dt.Rows.Add(dr); } else { int totalCount = 0; int pageCount = 0; //客户 dt = CustomBusiness.BaseBusiness.GetCustomersDatable(qicCustomer.SearchType, qicCustomer.Type, qicCustomer.SourceID, qicCustomer.StageID, qicCustomer.Status, qicCustomer.Mark, qicCustomer.ActivityID, qicCustomer.UserID, qicCustomer.TeamID, qicCustomer.AgentID, qicCustomer.BeginTime, qicCustomer.EndTime, qicCustomer.Keywords, qicCustomer.OrderBy, int.MaxValue, 1, ref totalCount, ref pageCount, CurrentUser.UserID, CurrentUser.AgentID, CurrentUser.ClientID, qicCustomer.ExcelType); if (!dt.Columns.Contains("province")) { dt.Columns.Add("province", Type.GetType("System.String")); } if (!dt.Columns.Contains("citys")) { dt.Columns.Add("citys", Type.GetType("System.String")); } if (!dt.Columns.Contains("counties")) { dt.Columns.Add("counties", Type.GetType("System.String")); } foreach (DataRow drRow in dt.Rows) { var city= CommonBusiness.GetCityByCode(drRow["CityCode"].ToString()); if (city != null) { drRow["province"] = city.Province; drRow["citys"] = city.City; drRow["counties"] = city.Counties; } } } buffer = excelWriter.Write(dt, dic); var fileName = filleName + (test ? "导入模版" : "") + DateTime.Now.ToString("yyyyMMdd"); if (!Request.ServerVariables["http_user_agent"].ToLower().Contains("firefox")) fileName = HttpUtility.UrlEncode(fileName); this.Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx"); return File(buffer, "application/ms-excel"); }
public ActionResult ExportFromProduct(bool test = false, string model = "", string filleName = "产品", string filter = "") { JavaScriptSerializer serializer=new JavaScriptSerializer(); Dictionary<string, ExcelFormatter> dic = new Dictionary<string, ExcelFormatter>(); FilterProduct qicProduct = serializer.Deserialize<FilterProduct>(filter); Dictionary<string, ExcelModel> listColumn = new Dictionary<string, ExcelModel>(); if (string.IsNullOrEmpty(filter)) { listColumn = GetColumnForJson("product", ref dic, model, test ? "testexport" : "export", CurrentUser.ClientID); } else { qicProduct = serializer.Deserialize<FilterProduct>(filter); listColumn = GetColumnForJson("product", ref dic, !string.IsNullOrEmpty(model) ? model : "Item", test ? "testexport" : "export", CurrentUser.ClientID); } string ipPath = ""; var excelWriter = new ExcelWriter(); foreach (var key in listColumn) { excelWriter.Map(key.Key, key.Value.Title); } byte[] buffer; DataTable dt = new DataTable(); //模版导出 if (test) { DataRow dr = dt.NewRow(); foreach (var key in listColumn) { DataColumn dc1 = new DataColumn(key.Key, Type.GetType("System.String")); dt.Columns.Add(dc1); dr[key.Key] = key.Value.DefaultText; } dt.Rows.Add(dr); } else { int totalCount = 0; int pageCount = 0; ipPath= Server.MapPath("~"); dt = new ProductsBusiness().GetProductListDataTable(qicProduct.CategoryID, qicProduct.BeginPrice, qicProduct.EndPrice, qicProduct.Keywords, qicProduct.OrderBy, qicProduct.IsAsc, PageSize, qicProduct.PageIndex, ref totalCount, ref pageCount, CurrentUser.ClientID); } buffer = excelWriter.Write(dt, dic, ipPath); var fileName = filleName + (test ? "导入模版" : "")+DateTime.Now.ToString("yyyyMMdd"); if (!Request.ServerVariables["http_user_agent"].ToLower().Contains("firefox")) fileName = HttpUtility.UrlEncode(fileName); this.Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".xlsx"); return File(buffer, "application/ms-excel"); }