导出到Excel - IE8

时间:2011-04-18 14:20:36

标签: jquery asp.net-mvc-2 internet-explorer-8 export-to-excel

以下导出代码适用于IE7和FF,但不适用于IE8。需要改变什么才能在IE8中工作?

public override void ExecuteResult(ControllerContext context)
        {
            this.WriteFile(HtmlTable);
        }

        void WriteFile(string content)
        {
            HttpContext context = HttpContext.Current;
            context.Response.Clear();
            context.Response.AddHeader("content-disposition", "attachment;filename=\"" + _fileName + "\"");
            context.Response.Charset = "";
            //context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            context.Response.ContentType = "application/ms-excel";
            context.Response.Write(content);
            context.Response.End();
        }

这就是我们从前端称呼它的方式:

function resultsGridExportToExcel()
        {
            var exportUrl = '/extranet/mvc/Indications.cfc/SavedIndicationsExportToExcel?id=3'; 
            var postData = jQuery('#resultsGrid').jqGrid('getGridParam', 'postData'); 
            $.each(postData, function(key, value) 
            { 
                exportUrl += '&'+key+'='+encodeURIComponent(value); 
            }); 
            $('#SaveIndicationsExportForm').attr('action', exportUrl).submit(); 
        }

这是控制器方法:

[HttpPost]
        public System.Web.Mvc.ActionResult SavedIndicationsExportToExcel(string sidx, string sord, int page, int rows)
        {
            SavedIndication indication = new SavedIndication();

            var jqGridData = indication.GetSavedIndications(sidx, sord, 1, Int32.MaxValue);
            var gridDefinition = SavedIndication.GridDefinition;

            string filename = "Indications Calculator - Saved Indications";

            string htmlTable = jqGridData.RenderHtmlTable(gridDefinition.RetrieveColumnHeaders());
            htmlTable = Chatham.Web.Controllers.ExcelResult<string>.RemoveImages(htmlTable);
            return new ExcelResult() { FileName = filename, HtmlTable = htmlTable };
        }

它一直调试,没有错误,运行正常,但不会在IE8中生成任何输出,仅在IE7和FF中

1 个答案:

答案 0 :(得分:0)

看起来这是IETester的一个问题。

它不喜欢弹出窗口,并且必须弹出下载屏幕。在真正的IE机器上,这很有效。