日期:2014-05-17 浏览次数:21372 次
System.IO.StreamWriter sw = new System.IO.StreamWriter("a.txt", false, System.Text.Encoding.GetEncoding("gb2312")); try { int len = 0; string line = ""; string temp = ""; for (int i = 0; i < lv.Columns.Count; i++) { temp = lv.Columns[i].Text; len = 30 - Encoding.Default.GetByteCount(temp) + temp.Length; //考虑中英文的情况 temp = temp.PadRight( len, ' '); line += temp; } sw.WriteLine(line); line = ""; for (int i = 0; i < lv.Items.Count; i++) { for (int j = 0; j < lv.Items[i].SubItems.Count; j++) { temp = lv.Items[i].SubItems[j].Text; len = 30 - Encoding.Default.GetByteCount(temp) + temp.Length; temp = temp.PadRight(len, ' '); line += temp; } sw.WriteLine(line); line = ""; } sw.Flush(); } finally { if (sw != null) sw.Close(); }