从按钮单击Windows窗体打开excel文件

时间:2013-06-28 10:33:59

标签: c# winforms excel

private void btnOpenReport_Click(object sender, EventArgs e)
{  
    if (System.IO.File.Exists(outputFilePath))
    {
        Process.Start(new ProcessStartInfo("excel.exe", " /select, " + outputFilePath.Replace("\\\\", "\\")));
     }
}

1 个答案:

答案 0 :(得分:4)

可能你应该直接用属性UseShellExecutetrue启动Excel文件,这是默认的,它将启动默认的关联程序,很可能是Excel本身:

Process.Start(outputFilePath);

另一个问题是你做Replace的原因,但这可能是偏离主题的。