我实际上正在使用Microsoft.Office.Interop.Excel编写一个程序,该程序创建所需的特定excel文件。这很好。

我的程序创建,然后保险箱并关闭新的excel文件(工作正常)。

 sheet.SaveCopyAs(path);
 sheet.Saved = true;
 sheet.Close(true, misValue, misValue);
 excel.Quit();


成功创建新的Excel文件后,将打开一个DialogResult框,询问我是否要打开新的Excel文件

DialogResult dr = MessageBox.Show("Open new file?", "text", MessageBoxButtons.YesNo);
          {
             if (DialogResult == DialogResult.Yes)
             {
                  Process.Start(path);
             }
             else if (DialogResult == DialogResult.No)
             {
                   this.Close();
             }


但是,当我按YES时,什么也没有发生,新文件不会打开。

我在表格上尝试了一个额外的按钮

 private void button4_Click(object sender, EventArgs e)
        {
            Process.Start(path);
        }


这种方法有效,但是为什么DialogResult Box无法打开我的新Excel文件?

最佳答案

您的对话框结果值存储在dr中,因此您应该比较dr

DialogResult dr = MessageBox.Show("Open new file?", "text",
                                  MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
    Process.Start(path);
}
else if (dr == DialogResult.No)
{
     this.Close();
}

关于c# - 使用DialogResult C#启动进程,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52855146/

10-10 11:10
查看更多