0

I should convert a csv file to an excel file (.xls). At this moment I used this code:

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();

the problem is that it creates a file with only one column.

enter image description here

I would instead like to create the file with already divided columns at each semicolon without having to do it by hand after clicking on Data -> Text in columns -> ...

enter image description here

Thanks

L Y E S - C H I O U K H
  • 4,765
  • 8
  • 40
  • 57
  • Maybe you can look here for your answer: https://stackoverflow.com/questions/769621/dealing-with-commas-in-a-csv-file – N. Krh Mar 19 '18 at 11:38

1 Answers1

0

Mention the xlFileFormat and delimiter value

  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);
Sushma
  • 76
  • 1
  • 9