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();
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM