使用c#将csv转换为带有分隔列的Excel

时间:2018-03-19 11:18:01

标签: c# excel csv

我应该将csv文件转换为excel文件(.xls)。 此刻我使用了这段代码:

Excel.Application app = new Excel.Application();
Excel.Workbook wb = app.Workbooks.Open(fileOriginal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
wb.SaveAs(fileExcel, Excel.XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
wb.Close();
app.Quit();

问题是它创建的文件只有一列。

enter image description here

我想改为在每个分号上创建已经分割的列的文件,而不必在点击数据后手动完成 - >列中的文字 - > ...

enter image description here

由于

1 个答案:

答案 0 :(得分:0)

提及xlFileFormat和分隔符值

  Microsoft.Office.Interop.Excel.Workbook wb = app.Workbooks.Open(fileOriginal, Type.Missing,
            Type.Missing,Microsoft.Office.Interop.Excel.XlFileFormat.xlCSV, Type.Missing, Type.Missing, 
            Type.Missing, Type.Missing,";"
            , Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);