我在交换文件时遇到问题。从XLS到XLSX

时间:2019-06-07 13:15:57

标签: c# asp.net .net asp.net-mvc controller

我试图在应用程序代码中进行更改,因为无论如何我都尝试过并且没有成功。我的系统上有一个报告选项卡,但是它仅导出XLS文件,并且由于XLS限制为65,000行,因此我需要切换到XLSX。当他安装XLS时,我将展示其控制器的一部分。我无法显示我的Service方法,因为它很大,您会迷路。

[CustomAuthorize(TipoFuncao.PRINT)]
public ActionResult Index(FiltroRptManifesto filtro)
{
    byte[] result = null;
    bool overflowMonth = false;
    IWorkbook workbook = new XSSFWorkbook();

    try
    {                
        RptManifestoService rptManifestoService = new RptManifestoService(ModelState);
        result = rptManifestoService.GeraExcel(Server.MapPath("~/Content/RptManifesto.xls"), filtro, ViewBag.Usuario);
        if (ModelState.IsValid)
        {
             if (ValidateDate(ModelState["DtProtocoloIni"].Value, ModelState["DtProtocoloFin"].Value).Days > 540)
             {
                 overflowMonth = true;
                 throw new Exception();
             };

             Response.AppendCookie(new HttpCookie("downloadToken", filtro.DownloadToken));                                    
             return File(result, "application/vnd.ms-excel", "Manifesto.xls");
        }
    }
//...

1 个答案:

答案 0 :(得分:0)

我从来没有使用过NPOI,所以我可能是错的,但是如果您这样做会发生什么事情

var fileName = "Manifesto.xlsx";
return File(result, MimeMapping.GetMimeMapping(fileName), fileName);

return File(
        result, 
        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 
        "Manifesto.xlsx");