1 #region 导出数据到电子表格 2 /// <summary> 3 /// 导出数据到电子表格 4 /// </summary> 5 /// <returns></returns> 6 [HttpGet] 7 public ActionResult ExportDataToExcel() 8 { 9 List<SupplierModel> supplierModels = supplierBLL.GetAll(); 10 11 //通过AppSettings 获取文件路径 12 string path = ConfigHelper.GetStringByAppSettings("ExportExcel"); 13 14 //调用随机名方法拼接表格名 15 string sheetName = StringHelper.GetRandomString() + ".xlsx"; 16 17 //实例化表格帮助类 传递路径 18 ExcelHelper excelHelper = new ExcelHelper(path + sheetName); 19 20 //返回结果 21 int n = excelHelper.ListToExcel(supplierModels, sheetName); 22 return Json(n, JsonRequestBehavior.AllowGet); 23 } 24 #endregion