【问题标题】:ShellEx: Starting Excel minimized or hiddenShellEx:最小化或隐藏启动 Excel
【发布时间】:2010-09-15 16:07:57
【问题描述】:

使用以下代码,我可以在 C# 中运行 Excel:

System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.Start();

我可以使用任何命令行参数使 Excel 开始隐藏或最小化吗?

(编辑:尝试p.StartInfo.WindowStyle,但没有效果。)

我需要在不使用 COM 的情况下启动 Excel,因为通过 COM 启动 Excel 时,none of the XLA add-ins are loaded

【问题讨论】:

    标签: c# shell process excel-2007 command-line-arguments


    【解决方案1】:

    您可以将WindowStyle 属性设置为MinimizedHidden。像下面这样:

    ProcessStartInfo p = new ProcessStartInfo("excel.exe");
    p.WindowStyle = ProcessWindowStyle.Minimized;
    Process.Start(p);
    

    【讨论】:

    • 感谢您的回答。不幸的是,它似乎根本没有效果(顺便说一句:这是p.StartInfo.WindowStyle,而不是p.WindowStyle
    • 此代码取自工作程序。请注意此代码与您的代码之间的细微差别。它不会创建 Process 类的实例。相反,它使用ProcessStartInfo 类,并将其传递给Process 的静态Start 方法。我用 Office 2007(在 Windows XP 上)和 2010(在 Windows 7 上)对其进行了测试。
    • ... 做到了!虽然我不明白Process.Start(new ProcessStartInfo(FooBar))new Process() { StartInfo.Foo = Bar }.Start() 之间的技术区别,但你的版本对我来说很合适。
    • 既然你已经成功使用了这个代码,你能帮我解决我现在面临的另一个问题吗? stackoverflow.com/questions/3736550/…
    猜你喜欢
    • 2013-04-02
    • 2010-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-05
    • 2011-08-26
    • 2013-09-08
    • 2020-08-02
    相关资源
    最近更新 更多