API 通过get请求,注意用到一个[FromUri]特性,使GET接收实体参数
/// <summary> /// 导出 /// </summary> /// <param name="model"></param> [HttpGet] public void ExportExcel([FromUri]FilterModel model) { API 直接调用业务层方法 }
/// <summary> /// 导出数据 /// </summary> /// <param name="filter"></param> /// <returns></returns> public void ExcelStream(FilterModel filter) { string filePath= HttpContext.Current.Server.MapPath("~/Export/List.xlsx"); Workbook workbook = new Workbook(filePath); Worksheet worksheet = workbook.Worksheets[0]; Cells cells = worksheet.Cells; PageSource<CaseModel> source = GetCaseList(filter); int i = 1; foreach (CaseModel model in source.DataSource) { cells[i, 0].PutValue(i); cells[i, 1].PutValue(model.1); cells[i, 2].PutValue(model.2); i++; } workbook.Save(HttpContext.Current.Response, "列表.xlsx", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Xlsx)); HttpContext.Current.Response.End(); }