在新窗口中打开Excel文件(即不是现有的Excel实例) [英] Open excel file in new window (i.e. not an existing Excel instance)

查看:341
本文介绍了在新窗口中打开Excel文件(即不是现有的Excel实例)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图确保传递到我的应用程序的excel文件在其自己的窗口中打开,而不是在现有的Excel实例中打开.有没有办法告诉流程做到这一点?以下代码始终使用现有实例(如果存在).

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 Process to do this? The following code always uses an existing instance if present.

Process process = new Process();
process.StartInfo.FileName = myExcelFile;
process.Start();

谢谢

马特

推荐答案

尝试以下操作.

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

其他选项是,如果您使用Interop(即Microsoft.Office.Interop.Excel.dll),则可以执行以下操作.这将始终在新实例中打开文件.

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);

这篇关于在新窗口中打开Excel文件(即不是现有的Excel实例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆