简体   繁体   English

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

[英]Microsoft.Office.Interop.Excel - *.csv file opening

I create *.csv file, but when I open it using Microsoft.Office.Interop.Excel , it's formatting is wrong, because of ignoring the delimiter ; 我创建了*.csv文件,但是当我使用Microsoft.Office.Interop.Excel打开它时,由于忽略了分隔符,因此格式设置错误; .

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

Which parameter of Workbooks.Open should I change? 我应该更改Workbooks.Open哪个参数?

Thank you for your suggestions. 谢谢你的建议。

The delimiter argument, which is the 9th one. 定界符参数,这是第9个。 Change "" to ";" ""更改为";" . For more info, check msdn 有关更多信息,请检查msdn

This is how it should be: 这应该是这样的:

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

Interop Excel has a format to open CSV files. 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);

Format and Delimiter combo should be working in all cases. 在所有情况下,格式和定界符组合都应该起作用。

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM