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[];
Cells cells = worksheet.Cells; PageSource<CaseModel> source = GetCaseList(filter);
int i = ;
foreach (CaseModel model in source.DataSource)
{
cells[i, ].PutValue(i);
cells[i, ].PutValue(model.1);
cells[i, ].PutValue(model.2); i++;
}
workbook.Save(HttpContext.Current.Response, "列表.xlsx", ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Xlsx));
HttpContext.Current.Response.End();
}