Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c中打开和编辑多个.csv文件#_C# - Fatal编程技术网

C# 在c中打开和编辑多个.csv文件#

C# 在c中打开和编辑多个.csv文件#,c#,C#,我的理想是:打开一些.csv文件(5个或6个或更多),向所有打开的文件添加2个新列,最后保存它。这是我的密码 OpenFileDialog fopen = new OpenFileDialog(); fopen.Multiselect = true; fopen.Filter = "(All type)|*.*"; fopen.ShowDialog(); if (fopen.FileName != null) { Excel.Applicati

我的理想是:打开一些.csv文件(5个或6个或更多),向所有打开的文件添加2个新列,最后保存它。这是我的密码

OpenFileDialog fopen = new OpenFileDialog();
fopen.Multiselect = true;                      
fopen.Filter = "(All type)|*.*";
fopen.ShowDialog();
if (fopen.FileName != null)
{
    Excel.Application app = new Excel.Application();
    Excel.Workbook wb = app.Workbooks.Open(fopen.FileName);
    Excel.Worksheet sheet = wb.Sheets[1];
    Excel.Range range = sheet.UsedRange;

    int column = range.Columns.Count;
    int row = range.Rows.Count;

    textBox1.Text = fopen.FileName;

    //textBox2.Text = row.ToString();
    //textBox3.Text = column.ToString();

    range.Cells.set_Item(1, column + 1, "Mo_stMoC");
    range.Cells.set_Item(1, column + 2, "Mo_stMoCCpl");

    for (int i = 2; i <= row; i++)
    {
        range.Cells.set_Item(i, column + 1, "0");
        range.Cells.set_Item(i, column + 2, "0");
    }
    wb.Save();
    wb.Close();  
    app.Workbooks.Close();
    app.Quit();
}
OpenFileDialog fopen=newopenfiledialog();
fopen.Multiselect=true;
fopen.Filter=“(所有类型)|*.*”;
fopen.ShowDialog();
如果(fopen.FileName!=null)
{
Excel.Application app=新建Excel.Application();
Excel.Workbook wb=app.Workbooks.Open(fopen.FileName);
Excel.Worksheet sheet=wb.Sheets[1];
Excel.Range范围=sheet.UsedRange;
int column=range.Columns.Count;
int row=range.Rows.Count;
textBox1.Text=fopen.FileName;
//textBox2.Text=row.ToString();
//textBox3.Text=column.ToString();
范围.单元格.集合项目(1,第+1列,“Mo_stMoC”);
范围。单元格。集合项(1,第+2列,“Mo_stMoCCpl”);
对于(int i=2;i您正在打开的文件,请循环使用fopen.FileName,而不仅仅是使用fopen.FileName

 foreach (String file in fopen.FileNames) 
{
  //do your thing
  //edit
}
此外,最好只过滤csv文件,而不是全部

 fopen.Filter = "CSV Files (*.csv)|*.csv";

你没有循环。。。