Changeset 15 for Common/CsvExport.cs
- Timestamp:
- Jun 18, 2024, 12:15:33 PM (5 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/CsvExport.cs
r14 r15 6 6 namespace Common 7 7 { 8 class CsvExport8 public class CsvExport 9 9 { 10 public void ListViewToCsv(ListView listView, string filePath, bool includeHidden)10 public static void ListViewToCsv(ListView listView, string filePath, bool includeHidden) 11 11 { 12 12 // Make header string … … 15 15 16 16 // Export data rows 17 foreach (ListViewItem listItem in listView.Items) 18 WriteCsvRow(result, listView.Columns.Count, i => includeHidden || listView.Columns[i].Width > 0, i => listItem.SubItems[i].Text); 17 for (int j = 0; j < listView.Items.Count; j++) 18 { 19 WriteCsvRow(result, listView.Columns.Count, i => includeHidden || listView.Columns[i].Width > 0, 20 i => listView.Items[j].SubItems[i].Text); 21 } 19 22 20 23 File.WriteAllText(filePath, result.ToString()); 21 24 } 22 25 23 public void DataGridViewToCsv(DataGridView dataGridView, string filePath, bool includeHidden)26 public static void DataGridViewToCsv(DataGridView dataGridView, string filePath, bool includeHidden) 24 27 { 25 28 // Make header string … … 34 37 } 35 38 36 private void WriteCsvRow(StringBuilder result, int itemsCount, Func<int, bool> isColumnNeeded, Func<int, string> columnValue)39 private static void WriteCsvRow(StringBuilder result, int itemsCount, Func<int, bool> isColumnNeeded, Func<int, string> columnValue) 37 40 { 38 41 bool isFirstTime = true; … … 46 49 isFirstTime = false; 47 50 48 result.Append( String.Format("\"{0}\"", columnValue(i).Replace("\"", "\"\"")));51 result.Append($"\"{columnValue(i).Replace("\"", "\"\"")}\""); 49 52 } 50 53 result.AppendLine(); 51 54 } 52 53 55 } 54 56 }
Note:
See TracChangeset
for help on using the changeset viewer.