4
votes

I've used the Open XML SDK 2.0 to create a new spreadhsheet and save to a users folder. i want to be able to open this automatically after saving. The file is in the xlsx format.

I tried

 SpreadsheetDocument.Open(fileName, true);

This isn't working at all. I'd like the code to open the file in whatever version of excel the user has - 2003, 2007 and 2010 (Assumption: 2003 will have the compatibility pack installed)

2

2 Answers

19
votes

If excel is set as the default viewer for xls files on the system you can open the file using Process class:

System.Diagnostics.Process.Start("myFile.xls");
1
votes

This just opens the Excel for internal read/write in your app, but I assume you want to open it for the user in Excel?

Then you would have to do something like this:

using System.Diagnostics;

class Program
{
    static void Main()
    {
       // A.
       // Open specified Word file.
       OpenMicrosoftWord(@"C:\Users\Sam\Documents\Gears.docx");
    }

    /// <summary>
    /// Open specified word document.
    /// </summary>
    static void OpenMicrosoftWord(string f)
    {
       ProcessStartInfo startInfo = new ProcessStartInfo();
       startInfo.FileName = "WINWORD.EXE";
       startInfo.Arguments = f;
       Process.Start(startInfo);
    }
}

http://www.dotnetperls.com/process-start