亲宝软件园·资讯

展开

C#中把日志导出到txt文本 C#中把日志导出到txt文本的简单实例

人气:4
想了解C#中把日志导出到txt文本的简单实例的相关内容吗,在本文为您仔细讲解C#中把日志导出到txt文本的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:C#,日志,txt,下面大家一起来学习吧。

复制代码 代码如下:

/// <summary>
        /// 打日志
        /// </summary>
        /// <param name="log"></param>

        //首先还是要using system.io;    
        public void Write(ArrayList log)
            {
                      //将文件保存在桌面,文件名称为当前时间.txt
                FileStream fs = new
                                  FileStream("C:\\Users\\ailin\\Desktop\\" +
                                  DateTime.Now.ToLongTimeString().Replace(":", "") + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    StreamWriter sw = new StreamWriter(fs, Encoding.Default);
                    foreach( string i in log)
                    {

                            sw.Write(i.ToString());

                    }
                     DateTime dt1 = DateTime.Now;
                     sw.WriteLine();
                     sw.WriteLine("操作人:cxx");
                     sw.WriteLine("日期:"+Convert.ToString(dt1));
                     sw.Flush();
                     sw.Close();
            }

            //string sSaveExcelName =
        //"C:\\" + DateTime.Now.ToShortDateString().Replace("-", "") + DateTime.Now.ToLongTimeString().Replace(":", "") + ".xls";
         public static ArrayList aChg_Slab_Len = new ArrayList();
            private void button2_Click(object sender, EventArgs e)
            {


                    ArrayList cx = new ArrayList();

                    for (int i = 0; i < ss1.ActiveSheet.RowCount; i++)
                    {
                        for (int j = 0; j < ss1.ActiveSheet.ColumnCount; j++)
                        {
                           cx.Add(ss1.ActiveSheet.Cells[i, j].Text);
                           cx.Add("  ");
                        }
                        cx.Add("\r\n");

                    }
                    //执行导出日志的操作
                    Write(cx);
                    return;

            }

加载全部内容

相关教程
猜你喜欢
用户评论