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
  • 相关阅读:
    BZOJ 3529 数表
    BZOJ 3832 Rally
    BZOJ 1086 王室联邦
    BZOJ 2738 矩阵乘法
    2656565
    小L的区间求和
    小L的直线
    Co-prime 杭电4135
    POJ 跳蚤
    B
  • 原文地址:https://www.cnblogs.com/beast-king/p/3456109.html
Copyright © 2011-2022 走看看