|I am trying to open an Excel workbook to use in my C# application. I have found many examples of opening a blank (new) workbook using new Excel.Application(). How do I open a specific xls file using Excel.Application ?
//open Excel with new workbook
Excel.Application excel = new Excel.Application();
excel.Application.Visible = true;
I have been able to open a specific file using Process
string path = "C:\\";
string file = "flow.xls";
System.Diagnostics.Process xlProcess = new System.Diagnostics.Process();
xlProcess.EnableRaisingEvents = false;
xlProcess.StartInfo.FileName = "excel";
xlProcess.StartInfo.Arguments = path + file;
as long as the path has no spaces.
But with a path like
string path = "C:\\Documents and Settings\\userName\\My Documents\\data\\FlowData\\flow.xls";
I also tried a verbatim string
string path = @"C:\Documents and Settings\userName\My Documents\data\FlowData\flow.xls";
How do I add the spaces to the path?
When you come to a fork in the road, take it! Y. Berra