zoukankan      html  css  js  c++  java
  • webapi aspose导出excel表格

    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();
            }
  • 相关阅读:
    【待整理】转义字符
    关系运算符 与 逻辑运算符
    浏览器相关
    正则表达式
    样式定义——多重浏览器
    事件
    属性定义
    数组
    日期
    构造函数
  • 原文地址:https://www.cnblogs.com/njcxwz/p/6208125.html
Copyright © 2011-2022 走看看