zoukankan      html  css  js  c++  java
  • c# Asp.net生成Excel

        public static void ProductTeacherReport(DataTable dts)
        {

            DataTable dt 
    = dts;
            
    if (dt.Rows.Count == 0return;
            System.Text.StringBuilder sb 
    = new System.Text.StringBuilder();
            MemoryStream ms 
    = new MemoryStream();
            
    foreach (DataColumn dc in dt.Columns)
            {
                sb.Append(dc.ColumnName 
    + Convert.ToChar(9));
            }

            
    for (int i = 0; i < dt.Rows.Count; i++)
            {
                sb.Append(
    "\r");
                
    for (int j = 0; j < dt.Columns.Count; j++)
                {
                  
                    sb.Append( dt.Rows[i][j].ToString() 
    + Convert.ToChar(9));
                }
            }
            StreamWriter sw 
    = new StreamWriter(ms);
            sw.Write(sb.ToString());

            
    string fileName ="teacher_" + DateTime.Now.Ticks + ".xls";
            HttpContext.Current.Response.AddHeader(
    "Content-Disposition""attachment;fileName=" + fileName);
            HttpContext.Current.Response.ContentEncoding 
    = System.Text.Encoding.Unicode;
            HttpContext.Current.Response.ContentType 
    = "application/ms-excel";
            HttpContext.Current.Response.BinaryWrite(ms.ToArray());
        }
    没有时间写注释说明,上班偷偷发的哦
  • 相关阅读:
    python学习之路-day1-python基础1
    JSON.NET基本使用
    tortoiseSVN 设置ignore
    一个简单的身份证校验
    一个HttpWebRequest工具类
    linq to NHibernate
    python-plot and networkx绘制网络关系图
    DDoS攻击及防御措施
    白帽子原则
    认识特洛伊木马
  • 原文地址:https://www.cnblogs.com/newmin/p/1518591.html
Copyright © 2011-2022 走看看