【问题标题】:Xls Export in not running on the serverXls Export 在服务器上未运行
【发布时间】:2016-12-08 09:08:57
【问题描述】:
 public ActionResult ExportToExcel()
    {   
        GridView gv = new GridView();
        gv.DataSource = db.Details.Select(x => new
        {
            x.Title,
            Category = x.Category.Title,
            SubCategory = x.SubCategory.Title,
            x.Count,
            x.Price,
            Automobiles = x.Automobiles.Count,
            x.Description
        }).ToList();
        gv.DataBind();
        Response.ClearContent();
        Response.Buffer = true;            
        Response.AddHeader("content-disposition", "attachment; filename=Marklist.xls");
        Response.ContentType = "application/ms-excel";
        Response.Charset = "";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        gv.RenderControl(htw);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();
        return Json(true);
    }

Export 在本地运行良好。它不适用于 Azure。下载一个空文件。告诉我有什么问题?

【问题讨论】:

  • 这是在使用 COM 吗?
  • 还需要安装 Excel 才能在本地工作吗?
  • @evilSnobu 不,这显然不使用 COM 或 Excel 互操作。
  • 你在服务器上调试过吗?确认您实际上已从数据库中检索到数据?为什么要生成 HTML 文件并使用 XLS 扩展名提供它们?这是一个糟糕的做法,微软已经发布了一个更新,这几乎无法接受。为什么要从方法返回 JSON 并结束响应而不是返回文件结果?为什么在 ASP.NET MVC 中使用 GridView?

标签: c# asp.net-mvc azure xls


【解决方案1】:

您的问题可能与最近的 Microsoft Excel 安全更新有关。

见...https://stackoverflow.com/a/38467132/6610346

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-29
    • 2018-08-13
    • 2014-04-17
    • 1970-01-01
    • 2021-01-14
    • 2017-06-15
    • 2014-12-03
    • 2016-05-06
    相关资源
    最近更新 更多