zoukankan      html  css  js  c++  java
  • .NET DataSet DataTable 导出excel

    public void CreateExcel(DataSet ds, string FileName)
    {
    HttpResponse resp;
    resp = Page.Response;
    resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
    resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName+".xls");
    StringBuilder context = new StringBuilder("<table><thead><tr><th>序号</th><th>用户ID</th><th>部门</th><th>公司</th><th>最后登录日期</th></tr></thead><tbody>");
    //逐行处理数据
    int i = 0;
    foreach (DataRow row in ds.Tables[0].Rows)
    {
    context.Append("<tr><td>" + ++i + "</td><td>");
    context.Append(row["AccountId"].ToString() + "</td><td>");
    context.Append(row["Department"].ToString() + "</td><td>");
    context.Append(row["Company"].ToString() + "</td><td>");
    context.Append(row["LastLogOnTime"] == null ? " " : row["LastLogOnTime"].ToString() + "</td></tr>");
    }
    context.Append("</tbody></table>");
    resp.Write(context.ToString());
    resp.End();
    }

  • 相关阅读:
    Linux下定时删除指定目下n天前的文件
    日期时间格式化
    sed与awk
    Linux守护进程(init.d和xinetd)
    python-Json模块
    python3 urllib模块
    linux 命令 rsync
    Linux下scp的用法
    代码块重定向
    使用exec
  • 原文地址:https://www.cnblogs.com/hyd309/p/3469645.html
Copyright © 2011-2022 走看看