Open excel file in new window (i.e. not an existing Excel instance)

后端 未结 1 548
情深已故
情深已故 2021-01-20 20:55

I\'m trying to ensure that an excel file passed to my application is opened in it\'s own window rather than an existing Excel instance. Is there a way of telling the Proces

相关标签:
1条回答
  • 2021-01-20 21:23

    Try the following.

    Process process = new Process();
    Process.Start("Excel.exe", myExcelFile);
    

    Other option is, if you use Interop (i.e. Microsoft.Office.Interop.Excel.dll ), you can do it as follows. This will always open the file in a new instance.

    Excel.Application excelApp = new Excel.Application();
    excelApp.Visible = true;
    string workbookPath = (@"C:\Sample.xlsx");
    Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath,
        0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
        true, false, 0, true, false, false);
    
    0 讨论(0)
提交回复
热议问题