如何解决问题返回Filecontent,contentType,fileName;当我尝试导出时
我正在尝试使用asp.net MVC中的apiController导出Excel文件 这是我的代码:
[HttpPost]
[HttpRoute("report/historicalExpirations/excel")]
public Microsoft.AspNetCore.Mvc.IActionResult Excel([FromBody] HistoricalExpirationDto HeDto) {
string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
string fileName = "VencimientosHistoricos.xlsx";
var res = _reportRepository.HistoricalExpirations(HeDto.CompanyCode,HeDto.Date,HeDto.EntityCode);
using(var workbook = new XLWorkbook()) {
var worksheet = workbook.Worksheets.Add("Historico de Vencimientos");
var currentRow = 1;
#region Headers
worksheet.Cell(currentRow,1).Value = "Fecha";
worksheet.Cell(currentRow,2).Value = "Id";
worksheet.Cell(currentRow,3).Value = "Sector";
worksheet.Cell(currentRow,4).Value = "Proveedor";
worksheet.Cell(currentRow,5).Value = "Cuit Proveedor";
worksheet.Cell(currentRow,6).Value = "Proveedor Habilitado";
worksheet.Cell(currentRow,7).Value = "Codigo Recurso";
worksheet.Cell(currentRow,8).Value = "Tipo Recurso";
worksheet.Cell(currentRow,9).Value = "Recurso";
worksheet.Cell(currentRow,10).Value = "Recurso Habilitado";
worksheet.Cell(currentRow,11).Value = "Motivo";
#endregion
#region Body
foreach(var reg in res) {
currentRow++;
worksheet.Cell(currentRow,1).Value = reg.Date;
worksheet.Cell(currentRow,2).Value = reg.Id;
worksheet.Cell(currentRow,3).Value = reg.Sector;
worksheet.Cell(currentRow,4).Value = reg.Provider;
worksheet.Cell(currentRow,5).Value = reg.CuitProvider;
worksheet.Cell(currentRow,6).Value = reg.EnabledProvider;
worksheet.Cell(currentRow,7).Value = reg.ResourceCode;
worksheet.Cell(currentRow,8).Value = reg.ResourceType;
worksheet.Cell(currentRow,9).Value = reg.Resource;
worksheet.Cell(currentRow,10).Value = reg.EnabledResource;
worksheet.Cell(currentRow,11).Value = reg.Motive;
}
#endregion
using(var stream = new MemoryStream()) {
workbook.SaveAs(stream);
var content = stream.ToArray();
return File(content,contentType,fileName);
}
}
}
错误: GravedadCódigoDescripciónProyecto ArchivoLíneaEstado suprimido 错误CS1955没有使用通用文件名“文件”,无法调用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。