zoukankan      html  css  js  c++  java
  • download excel file from datagrid for webpage

    /// <summary>
    /// Summary description for WebExcelUtil.
    /// </summary>
    public sealed class WebExcelUtil
    {
    public static void GenerateExcel(DataSet objDS, HttpResponse objResponse)
    {
    if (objDS==null) return;
    objResponse.Clear();
    objResponse.Buffer = false;
    objResponse.Charset = "GB2312";
    objResponse.AppendHeader("Content-Disposition", "attachment;filename=Result.xls");
    objResponse.ContentEncoding = Encoding.GetEncoding("GB2312");
    objResponse.ContentType = "application/vnd.ms-excel";
    objResponse.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");

    StringWriter objStringWrite = new StringWriter();
    HtmlTextWriter objHtmlWriter = new HtmlTextWriter(objStringWrite);
    DataGrid objDataGrid = new DataGrid();

    objDataGrid.DataSource = objDS.Tables[0];
    objDataGrid.DataBind();
    objDataGrid.RenderControl(objHtmlWriter);
    objResponse.Write(objStringWrite.ToString());
    objResponse.End();
    }

    public static void GenerateExcel(DataGrid objDataGrid, HttpResponse objResponse)
    {
    objResponse.Clear();
    objResponse.Buffer = false;
    objResponse.Charset = "GB2312";
    objResponse.AppendHeader("Content-Disposition", "attachment;filename=Result.xls");
    objResponse.ContentEncoding = Encoding.GetEncoding("GB2312");
    objResponse.ContentType = "application/vnd.ms-excel";
    objResponse.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");

    StringWriter objStringWrite = new StringWriter();
    HtmlTextWriter objHtmlWriter = new HtmlTextWriter(objStringWrite);

    objDataGrid.RenderControl(objHtmlWriter);
    objResponse.Write(objStringWrite.ToString());
    objResponse.End();
    }
    }
  • 相关阅读:
    vue中computed计算属性和methods区别
    java解决跨域问题
    redis服务端开启
    使用excel生成商品条形码
    MySQL主键自增时SQL写法/当前时间写法
    修改MySQL数据库密码
    MySQL5.6.42解压版安装教程
    完全卸载MySQL数据库
    IDEA快捷键及xml文件中网址报错
    IDEA导入外部包
  • 原文地址:https://www.cnblogs.com/zhangchenliang/p/1808777.html
Copyright © 2011-2022 走看看