Changeset 15 for Common/CsvExport.cs


Ignore:
Timestamp:
Jun 18, 2024, 12:15:33 PM (5 months ago)
Author:
chronos
Message:
  • Modified: Updated files.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/CsvExport.cs

    r14 r15  
    66namespace Common
    77{
    8     class CsvExport
     8    public class CsvExport
    99    {
    10         public void ListViewToCsv(ListView listView, string filePath, bool includeHidden)
     10        public static void ListViewToCsv(ListView listView, string filePath, bool includeHidden)
    1111        {
    1212            // Make header string
     
    1515
    1616            // 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            }
    1922
    2023            File.WriteAllText(filePath, result.ToString());
    2124        }
    2225
    23         public void DataGridViewToCsv(DataGridView dataGridView, string filePath, bool includeHidden)
     26        public static void DataGridViewToCsv(DataGridView dataGridView, string filePath, bool includeHidden)
    2427        {
    2528            // Make header string
     
    3437        }       
    3538
    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)
    3740        {
    3841            bool isFirstTime = true;
     
    4649                isFirstTime = false;
    4750
    48                 result.Append(String.Format("\"{0}\"", columnValue(i).Replace("\"", "\"\"")));
     51                result.Append($"\"{columnValue(i).Replace("\"", "\"\"")}\"");
    4952            }
    5053            result.AppendLine();
    5154        }
    52 
    5355    }
    5456}
Note: See TracChangeset for help on using the changeset viewer.