using DS.Module.Core; using DS.Module.ExcelModule; using DS.Module.ExcelModule.Model; using DS.WMS.Core.Code.Interface; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using NPOI.HPSF; using System.Text; namespace DS.WMS.MainApi.Controllers { /// /// Excel服务 模块 /// public class ExcelController : ApiController { private readonly IExcelService _invokeService; /// /// 构造函数 /// /// public ExcelController(IExcelService invokeService) { _invokeService = invokeService; } /// /// 根据用户列导出Excel数据 /// /// 请求数据 /// [HttpPost] [Route("ExportExcelByColumn")] public DataResult ExportExcelByColumn([FromBody] ExportByColumnReq req) { return _invokeService.ExportExcelByColumn(req); } /// /// 根据用户列导出Excel文件流 /// /// 请求数据 /// [HttpPost] [Route("ExportExcelStreamByColumn")] public async Task ExportExcelStreamByColumn([FromBody] ExportByColumnReq req) { var result = _invokeService.ExportExcelStreamByColumn(req); HttpContext.Response.Headers.Add("Content-Length", result.Length.ToString()); HttpContext.Response.Headers.Add("Content-Type", "charset=UTF-8"); return File(result, "application/octet-stream;charset=UTF-8", Path.GetFileName(Path.GetRandomFileName() + ".xlsx")); //return new FileStreamResult(result, "application/octet-stream") { FileDownloadName = Guid.NewGuid().ToString() + ".xlsx" }; } } }