zoukankan      html  css  js  c++  java
  • C#写数据到Excel

    private void ImportToExcel(string strFileName, DataSet ds)
        {
            Stream myStream = System.IO.File.Create(strFileName);
            StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312"));
            string str = "";
            try
            {
                //写标题
                for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
                {
                    if (i > 0)
                        str += "\t";
                    str += ds.Tables[0].Columns[i].ColumnName;
                }
                sw.WriteLine(str);

                for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
                {
                    string strTmp = "";
                    for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
                    {
                        if (j > 0)
                            strTmp += "\t";
                        strTmp += ds.Tables[0].Rows[i][j].ToString();
                    }
                    sw.WriteLine(strTmp);
                }
                sw.Close();
                myStream.Close();
            }
            catch (Exception ex)
            { }
            finally
            {
                sw.Close();
                myStream.Close();
            }

        }

  • 相关阅读:
    监督学习——决策树理论与实践(上):分类决策树
    监督学习——随机梯度下降算法(sgd)和批梯度下降算法(bgd)
    Protobuf 从入门到实战
    Android 广播机制
    Java 并发编程——volatile/synchronized
    Android 手势识别—缩放
    Jquery 使用和Jquery选择器
    初识jQuery
    正则表达式
    正则表达式
  • 原文地址:https://www.cnblogs.com/jacker1979/p/1531832.html
Copyright © 2011-2022 走看看