繁体   English   中英

导出到Excel在服务器上不起作用

[英]Export to excel does not work on server

我有一个在两台服务器上运行的应用程序,一个是质量检查,另一个是生产。 问题是,当您要打开由应用程序在质量检查或PRD中下载的excel时,它会打开Excel,但没有任何反应,只是空白。

曾经有一段时间该应用程序可以将信息导出到Excel文件, 而从昨天开始不再存在 ,方法如下:

[Autorizacion]
public ActionResult ExportToExcelReports()
{
    IList<DTOReport> reports = null;

    try
    {
        reports = BusinessLogic.Report.GetReports(SessionHelper.Site.IdSite); 

        var title = "Reports";

        var report = new System.Data.DataTable(title);

        report.Columns.Add("Blah1", typeof(string));
        report.Columns.Add("Blah2", typeof(string));
        report.Columns.Add("Blah3", typeof(string));
        report.Columns.Add("Blah4", typeof(string));
        report.Columns.Add("Blah5", typeof(string));
        report.Columns.Add("Blah6", typeof(string));
        report.Columns.Add("Blah7", typeof(string));
        report.Columns.Add("Blah8", typeof(string));
        report.Columns.Add("Blah9", typeof(string));
        report.Columns.Add("Blah10", typeof(string));

        foreach (var item in reports)
        {
            var brandText = "";

            foreach (var brand in item.Brands)
            {
                brandText = brandText + (brandText != "" ? "," : "") + brand.Name;
            }

            report.Rows.Add(item.Name, item.Description, item.DateCreated, item.Type, item.Category, item.Latitude, item.Longitude, item.Locality, item.Province, brandText);
        }

        var grid = new GridView();
        grid.DataSource = report;
        grid.DataBind();

        Response.ClearContent();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment; filename=" + title + ".xls");
        Response.ContentType = "application/ms-excel";

        Response.Charset = string.Empty;
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);

        grid.RenderControl(htw);

        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();    
    }
    catch (Exception ex)
    {
        LogError(ex);
    }

    return View("Index", reports);
}

问题是,这在我的本地计算机上有效,我打开了我编译的项目,运行了它,并且它在使用相同的信息或生产数据的情况下也无法正常工作,因为它们共享相同的服务器数据库,因此在质量检查中也是如此。

GetReports运行完美,它没有输入try catch,它只在我的开发环境中起作用。 与服务器中的excel有关的东西吗?

可能与IIS或应用程序部署服务器有关吗?

http://www.computerhope.com/issues/ch001123.htm

您可以尝试上面的链接。 由于它曾经可以使用,所以可能更改了Excel的设置。 基本上,链接中有三件事可以尝试:

  1. 取消选中Excel中的“忽略DDE”选项,以便不会忽略调用它的外部应用程序。
  2. 检查文件关联中各种Excel文件类型(.xls,.xlsx,.xlsm等)的扩展名
  3. 修复Office Excel,以防其无法正常运行

好的,我在此链接中找到了答案: 从互联网打开excel文件会打开一个空白的excel窗口

问题出现了,当的Windows安装了此更新:Windows更新KB3115130(Excel 2010中) - https://www.microsoft.com/en-us/download/details.aspx?id=52809

“ Microsoft Excel 2010 32位版本中存在一个安全漏洞,当打开经过恶意修改的文件时,该漏洞可能允许运行任意代码。此更新解决了该漏洞。”

解决方案是(不建议)卸载该更新,或者:进入文件的属性(R单击-属性)单击“取消阻止”,单击“应用”(Josh Bucklen回答)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM