Microsoft.Office.Interop.Excel – * .csv文件打开

我创build*.csv文件,但是当我用Microsoft.Office.Interop.Excel打开它时,它的格式是错误的,因为忽略了分隔符;

 excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false,5,"","", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); 

我应该更改哪些Workbooks.Open参数?

谢谢你的build议。

分隔符参数,即第9个。 将""更改为";" 。 有关更多信息,请检查msdn

这是应该如何:

 excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false,5,"","", false, Excel.XlPlatform.xlWindows, ";", true, false, 0, true, false, false); 

Interop Excel具有打开CSV文件的格式。

 excel_app.Workbooks.Open( txtFile.Text, // Filename Type.Missing, Type.Missing, Excel.XlFileFormat.xlCSV, // Format Type.Missing, Type.Missing, Type.Missing, Type.Missing, txtDelimiter.Text, // Delimiter Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); 

格式和分隔符组合应该在所有情况下工作。

资源