/// <summary>
  /// Excel导出
  /// </summary>
  /// <param name="dt"></param>
  /// <returns></returns>
  public static void DataTableToExcel(DataTable dt, string ExcleName)
  {

   if (dt != null && dt.Rows.Count > 0)
   {
    MemoryStream ms = ExcelHelper.DataTableToExcel(dt);
    string fileName = ExcleName +
          HttpUtility.UrlEncode(DateTime.Now.ToString("yyyyMMddHHmmssfff"), System.Text.UTF8Encoding.UTF8);
    HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
    HttpContext.Current.Response.AddHeader("Content-Disposition",
     String.Format("attachment;filename={0}", fileName + ".xls"));
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.BinaryWrite(ms.GetBuffer());
    HttpContext.Current.ApplicationInstance.CompleteRequest();
   }
  }

相关文章:

  • 2022-12-23
  • 2021-11-27
  • 2021-11-29
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
相关资源
相似解决方案