You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.9 KiB
C#

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
{
/// <summary>
/// Excel服务 模块
/// </summary>
public class ExcelController : ApiController
{
private readonly IExcelService _invokeService;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="invokeService"></param>
public ExcelController(IExcelService invokeService)
{
_invokeService = invokeService;
}
/// <summary>
/// 根据用户列导出Excel数据
/// </summary>
/// <param name="req">请求数据</param>
/// <returns></returns>
[HttpPost]
[Route("ExportExcelByColumn")]
public DataResult<string> ExportExcelByColumn([FromBody] ExportByColumnReq req)
{
return _invokeService.ExportExcelByColumn(req);
}
/// <summary>
/// 根据用户列导出Excel文件流
/// </summary>
/// <param name="req">请求数据</param>
/// <returns></returns>
[HttpPost]
[Route("ExportExcelStreamByColumn")]
public async Task<IActionResult> 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" };
}
}
}