zoukankan      html  css  js  c++  java
  • ASP.NET---最简单的导出Excel

    #region 最简单的导出Excel
    publicvoid CreateExcel(DataTable _table, string FileName)
    {
    //FileName = Server.UrlEncode(FileName);
    HttpResponse response = Page.Response;
    response.Clear();
    response.Buffer
    =true;
    response.Charset
    ="GB2312";
    response.HeaderEncoding
    = System.Text.Encoding.GetEncoding("GB2312");
    response.ContentEncoding
    = System.Text.Encoding.GetEncoding("GB2312");
    response.AddHeader(
    "Content-Disposition", "attachment;filename="+ FileName);
    response.AddHeader(
    "Content-Type", "application/octet-stream;charset=GB2312");
    response.ContentType
    ="application/ms-excel";
    string ls_item ="";

    ls_item
    ="编号 险种 保单号 手续费 手续费率 佣金 备注 分组序号 ";
    response.Write(ls_item);
    ls_item
    ="";
    int i =1;
    foreach (DataRow row in _table.Rows)
    {
    ls_item
    = i.ToString() +" "+ row[3] +" "+ row[4] +" "+ row[7] +" "+ row[8] +" "+ row[9] +" "+ row[10] +" "+ i.ToString() +" ";
    response.Write(ls_item);
    i
    ++;
    }
    //写缓冲区中的数据到HTTP头文件中
    response.Flush();
    response.Clear();
    response.End();
    }
    #endregion
  • 相关阅读:
    困勉而行
    6.12
    js 实现表格筛选不请求后台数据
    VUE方法和函数汇总
    sql isnull用法
    js forEach的用法
    js _this.$nextTick 解决页面渲染问题
    element table 复选框单选
    js attr 追加属性
    C# 过滤器 验证页面权限
  • 原文地址:https://www.cnblogs.com/beast-king/p/3456109.html
Copyright © 2011-2022 走看看