简体   繁体   English

汇出Excel报表

[英]Exporting excel reports

I have a software ready in which i am exporting excel reports through code in ASP.NET . 我已经准备好一个软件,可以在其中通过ASP.NET中的代码导出excel报告。 Right now I am developing the entire on Localhost , so when i export the report it is downloading on my PC . 现在,我正在Localhost上进行整个开发,因此,当我导出报告时,它正在我的PC上下载。 I am just concerned if i run it on live server and than I export the excel reports , will it download on my Pc or on server. 我只是担心我是否在实时服务器上运行它,而不是导出excel报告,它将下载到我的PC或服务器上。

  public ActionResult ExportToExcel()
        {
            if (!General.ValidateSession())
            {
                return RedirectToAction("Login", "User");
            }
            string fDate = TempData["FromDate"].ToString();
            string tDate = TempData["toDate"].ToString();
            var grdview = new GridView();
            grdview.DataSource = this.GetList();
            grdview.DataBind();
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename= " + fDate + " - " + tDate + ".xls ");
            Response.ContentType = "application/ms-excel";
            Response.Charset = "";
            StringWriter strWriter = new StringWriter();
            HtmlTextWriter htmlWriter = new HtmlTextWriter(strWriter);
            grdview.RenderControl(htmlWriter);
            Response.Output.Write(strWriter.ToString());
            Response.Flush();
            Response.End();
            return RedirectToAction("DateRecords");
        }

when you host the application on server and On EXCEL Export, file will be downloaded to the user's machine from the server. 当您将应用程序托管在服务器上并且在EXCEL导出时,文件将从服务器下载到用户的计算机上。 not on to your local machine! 不在本地计算机上!

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

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