1 /// <summary> 2 /// 打日志 3 /// </summary> 4 /// <param name="log"></param> 5 6 //首先还是要using system.io;
public void Write(ArrayList log) 7 {
//将文件保存在桌面,文件名称为当前时间.txt 8 FileStream fs = new 9 FileStream("C:\Users\ailin\Desktop\" + 10 DateTime.Now.ToLongTimeString().Replace(":", "") + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite); 11 StreamWriter sw = new StreamWriter(fs, Encoding.Default); 12 foreach( string i in log) 13 { 14 15 sw.Write(i.ToString()); 16 17 } 18 DateTime dt1 = DateTime.Now; 19 sw.WriteLine(); 20 sw.WriteLine("操作人:cxx"); 21 sw.WriteLine("日期:"+Convert.ToString(dt1)); 22 sw.Flush(); 23 sw.Close(); 24 } 25 26 //string sSaveExcelName = 27 //"C:\" + DateTime.Now.ToShortDateString().Replace("-", "") + DateTime.Now.ToLongTimeString().Replace(":", "") + ".xls"; 28 public static ArrayList aChg_Slab_Len = new ArrayList(); 29 private void button2_Click(object sender, EventArgs e) 30 { 31 32 33 ArrayList cx = new ArrayList(); 34 35 for (int i = 0; i < ss1.ActiveSheet.RowCount; i++) 36 { 37 for (int j = 0; j < ss1.ActiveSheet.ColumnCount; j++) 38 { 39 cx.Add(ss1.ActiveSheet.Cells[i, j].Text); 40 cx.Add(" "); 41 } 42 cx.Add(" "); 43 44 } 45 //执行导出日志的操作 46 Write(cx); 47 return; 48 49 }