C # Excel Interop: opening and displaying a CSV file

Hi, I am writing a wrapper for excel interop, I want to open the csv file in excel and show it to the user. I have the basics, but when I set the visible value to true and excel appears, all the columns are clamped in the first and the separating commas are displayed.

here is my assistant.

public MyExcel(string filePath, bool readOnly) { _app = new Excel.Application(); _workbooks = _app.Workbooks; _workbook = _workbooks.Open(_filepath, 0, _readOnly, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", !_readOnly, false, 0, true, true, true); } public void Show() { _app.Visible = true; } 

any suggestions?

When I open the file with a double click, Excel handles everything correctly.

+4
source share
2 answers

You will need to use the OpenText method instead of Open if you want Excel to parse delimiters. Details: http://msdn.microsoft.com/en-us/library/bb223513%28v=office.12%29.aspx

Example in C #: http://msdn.microsoft.com/en-us/library/c9838808.aspx

+16
source

This is much simpler than if all you want to do is open the file ...

  Process proc = new Process(); proc.StartInfo = new ProcessStartInfo("excel.exe", "output.csv"); proc.Start(); 
+2
source

Source: https://habr.com/ru/post/1335003/


All Articles