为什么这会导致excel的出现被打开?
OpenFileDialog openFileDialog1 = new OpenFileDialog();
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
//EXCEL.EXE *32 is now showing in the task manager!
我正在从XLSX
中选择一个openfiledialog
文件,如上所示,我在任务管理器中看到了该过程。
有人可以告诉我这怎么可能?
答案 0 :(得分:1)
如果Excel已经打开,您应该尝试获取此实例,而不是创建新实例。
using System.Runtime.InteropServices;
...
Excel.Application xl = null;
try {
// Try to get an existing instance
xl = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
} catch (COMException ex) {
// Excel was not open. Open a new instance
xl = new Excel.ApplicationClass();
}