如何动态滑动csv文件到每个文件

本文关键字:文件 csv 何动态 动态 | 更新日期: 2023-09-27 18:08:44

我想动态滑动CSV文件到几个文件。

例子

CSV header H1 H2 H3 H4 H5 H6 H7 H8 H9

我选择H2和H4创建新的csv文件(H2.csv和H4.csv),所有数据属于这一列。

请告诉我一个好方法。

如何动态滑动csv文件到每个文件

您应该向我们展示您在代码中已经做了什么。我们最好能帮助你:)

这是一个尝试:

/// <summary>
/// Get a subtab of a another by specifing the columns index
/// </summary>
/// <param name="tab">a list of lines of your tab</param>
/// <param name="columns">the index of columns you want to keep (the order specified will match the result order of columns)</param>
/// <returns>a list of selected columns</returns>
public List<string[]> SubTab(List<string[]> tab, params int[] columns)
{
    // add error handling here like verifying that specified columns exist in tab
    var result = new List<string[]>();
    foreach (var line in tab)
    {
        var newLine = new string[columns.Length];
        for (int i = 0; i < columns.Length; i++)
        {
            newLine[i] = line[columns[i]];
        }
        result.Add(newLine);
    }
    return result;
}