簡體   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