【问题标题】:Loading is not ending on the browser after dowloading the Excel file下载 Excel 文件后,浏览器未结束加载
【发布时间】:2020-06-12 11:47:42
【问题描述】:

我正在使用网格视图将数据导出到 Excel。

所有数据都被导出到 Excel 中。

但是导出到Excel后,excelsheet直接打开到Excel中, 在浏览器中,即使 Excel 已经导出,我也会收到“请稍候...”符号。

这是我将数据导出到 Excel 中的代码:

          var gv = new GridView();
          gv.DataSource = Export_List;                    
          gv.DataBind();
          Response.ClearContent();
          Response.Buffer = true;
          Response.AddHeader("content-disposition", "attachment; filename=export.xls");
          Response.ContentType = "application/ms-excel";
          Response.Charset = "";
          StringWriter stringWriter = new StringWriter();
          HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
          gv.RenderControl(htmlTextWriter);
          Response.Output.Write(stringWriter.ToString());                    
          Response.End();

导出到Excel后,excelsheet直接在Excel中打开 在浏览器中,即使 Excel 已经导出,我也会收到“请稍候...”符号。

这是在_Layout.cshtml中加载符号的代码

<body  onbeforeunload="LoadSymbol()" onload="UnLoadSymbol()">

    <div id="pgLoad" style="margin: 0px; padding: 0px; position: fixed; right: 0px;
    top: 0px; width: 100%; height: 100%; background-color: #666666; z-index: 999999;
    opacity: .6; filter: alpha(opacity=70);display:none">
        <p style="position: absolute; top: 40%; left: 40%; color: White;">
            Please wait...<br>
            <i class="fa fa-circle-o-notch fa-spin fa-3x fa-fw"></i>
        </p>
    </div>
 some code

  <script language="javascript">        
        $("form").submit(function () { $("#pgLoad").show(); });

        document.onreadystatechange = function () {
            var iscomplete= document.readyState
            if (iscomplete== 'complete') {
                $("#pgLoad").hide();
            }
        }

            function LoadSymbol() {
                $("#pgLoad").show();
            }

            function UnLoadSymbol() {
                $("#pgLoad").hide();
            }
  </script>
</body>

这是导出按钮

@using (Html.BeginForm())
{
some code
<button type="submit" class="btn btn-primary" name="ExcelButton" value="Download as Excel" id="ExcelButton" > Download as Excel </button>
}                     

如果 excel 已经导出,我怎样才能摆脱这个“请稍候...”符号?

为什么Excel表格下载后直接打开到Excel,有什么办法可以显示下载的Excel进入Chrome的下载栏?

【问题讨论】:

    标签: javascript jquery asp.net-ajax httpresponse onreadystatechange


    【解决方案1】:

    您的 js 脚本不知道导出是否结束,您需要从 gridview 捕获响应并传递给 js。

    【讨论】:

    • 我怎样才能做到这一点?请详细说明
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    • 2013-07-27
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多