zoukankan      html  css  js  c++  java
  • CreatExcel()

    public void CreatExcel(System.Data.DataTable dt, System.Web.UI.Page thisPage)
        {
            System.IO.StringWriter sw = new System.IO.StringWriter();
            string rowStr = "";
            //取所有列名
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                rowStr = rowStr + dt.Columns[i] + "\t";
            }
            sw.WriteLine(rowStr);
            //取每行数据
            for (int j = 0; j < dt.Rows.Count; j++)
            {
                rowStr = "";
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    rowStr = rowStr + dt.Rows[j][i].ToString() + "\t";
                }
                sw.WriteLine(rowStr);
            }
            sw.Close();
            string filename = DateTime.Now.ToString("yyyyMMddhhmmss");
            thisPage.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
            thisPage.Response.ContentType = "application/ms-excel";
            thisPage.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            thisPage.Response.Write(sw);
            thisPage.Response.End();
        }


     

    keim,毕业于安徽科技学院理学院,2003年开始对Web开发有浓厚的兴趣,并专注于C#/java Web开发,软件架构设计、分布式相关、项目管理、前端设计等等,实战派...
  • 相关阅读:
    Understanding Paths in ASP.NET
    C#通过shell32来控制本地连接
    利用outlook发邮件
    角色扮演游戏引擎的设计原理[转载]
    Lvalues and Rvalues
    链接字符串里面不要加上connection timeout =0
    Winform获取当前拥有焦点的控件
    Spring 3.x jar 包详解 与 依赖关系
    Liferay环境搭建、简单说明与相关资料
    爆音(杂音)问题的推论与解决
  • 原文地址:https://www.cnblogs.com/zqmingok/p/1486244.html
Copyright © 2011-2022 走看看