开发者

Export to Excel - IE8

The following export code works in IE7 and FF, but not IE8. What needs to change for this to work in 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();
        }

This is how we call it from the front 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(); 
        }

And here is the controller method:

[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 };
        }

It debugs all the way through, no errors, runs fine, but doesn't generate any output in IE8, only in IE7 and FF


Looks like this was an issue with IETester.

It doesn't like popups and a screen had to popup for the download. On a REAL IE machine, this worked.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜