• Click Button to Export Excel Asp.net C#


        public void ExportExcel(string excelLocation)
        {
            try
            {
                Byte[] fileBytes = File.ReadAllBytes(excelLocation);
                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.Cookies.Clear();
                //Add the header & other information      
                Response.Cache.SetCacheability(System.Web.HttpCacheability.Private);
                Response.CacheControl = "private";
                Response.Charset = System.Text.UTF8Encoding.UTF8.WebName;
                Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
                Response.AppendHeader("Content-Length", fileBytes.Length.ToString());
                Response.AppendHeader("Pragma", "cache");
                Response.AppendHeader("Expires", "60");
                Response.AppendHeader("Content-Disposition",
                "attachment; " +
                "filename="ExcelReport.xlsx"; " +
                "size=" + fileBytes.Length.ToString() + "; " +
                "creation-date=" + DateTime.Now.ToString("R") + "; " +
                "modification-date=" + DateTime.Now.ToString("R") + "; " +
                "read-date=" + DateTime.Now.ToString("R"));
                Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                //Write it back to the client    
                Response.BinaryWrite(fileBytes);
                Response.Flush();
                Response.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    

      

  • 相关阅读:
    scapy-python
    多进程和多线程
    Python函数
    while循环
    打印print的另一种方式sys.stdout
    python3 pickle & struct
    正则表达式
    【牛客网刷题】两种排序方法
    使用Python matplotlib做动态曲线
    【牛客网刷题】一次难忘的编程教训
  • 原文地址:https://www.cnblogs.com/2zhyi/p/3642377.html
Copyright © 2020-2023  润新知