【发布时间】:2012-06-14 01:39:53
【问题描述】:
我需要打开一个没有新书的 Excel 应用程序。可能吗?这是我的代码:
public static Excel.Application InitializeTemplateExcelApp(string logFile)
{
Excel.Application app = null;
try
{
app = new Excel.Application();
app.Visible = true;
// reload all previously loaded addins
foreach (Excel.AddIn ai in app.AddIns)
{
if (ai.Installed != false)
{
ai.Installed = false;
ai.Installed = true;
app.Wait(30);
}
}
return app;
}
catch (Exception ex)
{
string errMessage = ex.Message.ToString();
File.AppendAllText(logFile, errMessage);
return null;
}
}
问题是当我初始化 excel 应用程序时,新工作簿会自动创建。之后我需要打开我自己的工作簿,它已经成为第二个打开的工作簿,我想避免这种情况。
感谢您的帮助,
伊利亚
【问题讨论】:
-
为什么不直接启动进程excel.exe?默认情况下它不应该打开工作簿。
-
有趣,但如果我只是运行 excel.exe 它实际上也打开了新书......可能是一些 excel 属性?另外,我需要确保之前安装的所有插件仍然存在。