简体   繁体   English

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

[英]Export to excel does not work on server

I have an app that runs on two servers, one is QA and the other one is Production. 我有一个在两台服务器上运行的应用程序,一个是质量检查,另一个是生产。 The problem is, when you want to open the excel that it is downloaded by the app in QA or PRD it opens Excel but nothing happens, just blank. 问题是,当您要打开由应用程序在质量检查或PRD中下载的excel时,它会打开Excel,但没有任何反应,只是空白。

There was a time where the app could export information to an Excel file, not anymore since yesterday the method is as follows: 曾经有一段时间该应用程序可以将信息导出到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);
}

The thing is, This works on my local machine, I open the project I compile it, I run it and it works flawlesly with the same information or Data from Production, the same happens with QA, because they share the same server-database. 问题是,这在我的本地计算机上有效,我打开了我编译的项目,运行了它,并且它在使用相同的信息或生产数据的情况下也无法正常工作,因为它们共享相同的服务器数据库,因此在质量检查中也是如此。

The GetReports is working perfectly, it doesnt enter in a try catch, it just works in my development environment. GetReports运行完美,它没有输入try catch,它只在我的开发环境中起作用。 Something related to excel in the servers maybe? 与服务器中的excel有关的东西吗?

Could it be something related to IIS or the servers where the app is deployed?. 可能与IIS或应用程序部署服务器有关吗?

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

You could try the above link. 您可以尝试上面的链接。 Since it used to work, perhaps Excel's settings have been changed. 由于它曾经可以使用,所以可能更改了Excel的设置。 Essentially in the link there are three things to try: 基本上,链接中有三件事可以尝试:

  1. Uncheck "Ignore DDE" option in Excel so that External applications that call it are not ignored. 取消选中Excel中的“忽略DDE”选项,以便不会忽略调用它的外部应用程序。
  2. Check file associations for the extensions for various Excel file types (.xls, .xlsx, .xlsm, etc.) 检查文件关联中各种Excel文件类型(.xls,.xlsx,.xlsm等)的扩展名
  3. Repair office excel in case it is not functioning properly 修复Office Excel,以防其无法正常运行

Ok I have found my answer in this link: Opening excel files from the internet opens a blank excel window 好的,我在此链接中找到了答案: 从互联网打开excel文件会打开一个空白的excel窗口

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

"A security vulnerability exists in Microsoft Excel 2010 32-Bit Edition that could allow arbitrary code to run when a maliciously modified file is opened. This update resolves that vulnerability." “ Microsoft Excel 2010 32位版本中存在一个安全漏洞,当打开经过恶意修改的文件时,该漏洞可能允许运行任意代码。此更新解决了该漏洞。”

The solution is either (not recommended) uninstall that update or: Go into the properties of the file (R click - properties) Click 'Unblock' Click 'Apply' (Answered by Josh Bucklen) 解决方案是(不建议)卸载该更新,或者:进入文件的属性(R单击-属性)单击“取消阻止”,单击“应用”(Josh Bucklen回答)

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

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