Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用interop服务和process.start()从c#win表单打开excel文件时出错_C#_.net_Winforms_Office Interop_System.diagnostics - Fatal编程技术网

使用interop服务和process.start()从c#win表单打开excel文件时出错

使用interop服务和process.start()从c#win表单打开excel文件时出错,c#,.net,winforms,office-interop,system.diagnostics,C#,.net,Winforms,Office Interop,System.diagnostics,我正在使用代码从临时文件夹打开excel工作表 我使用2个选项打开一个文件。 首先,我使用的是process.start(),如果这引发了错误,我将使用第二个interop服务。但两者都在使用excel 2013(365)的Win 8 pc上抛出错误 请帮我做这个 代码是 try { Process.Start("File Location"); } catch (Exception ex) { try { ExcelApp = new Microsoft.Office.

我正在使用代码从临时文件夹打开excel工作表

我使用2个选项打开一个文件。 首先,我使用的是
process.start()
,如果这引发了错误,我将使用第二个
interop服务
。但两者都在使用excel 2013(365)的Win 8 pc上抛出错误

请帮我做这个

代码是

try
{

   Process.Start("File Location");
}
catch (Exception ex)
{
  try
  {
    ExcelApp = new Microsoft.Office.Interop.Excel.Application();
    theWorkbook = ExcelApp.Workbooks.Open("File Location", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
    ExcelApp.Visible = true;
    ExcelApp.ActiveWindow.Zoom = 100;
    ExcelApp.ActiveWindow.WindowState = XlWindowState.xlMaximized;
    ExcelApp.WindowState = XlWindowState.xlMaximized;
  }
  catch (Exception)
  {
    theWorkbook.Close(false, Type.Missing, Type.Missing);
    throw;
  }
  finally
  {
    GC.Collect();
    GC.WaitForPendingFinalizers();
    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(theWorkbook);
    System.Runtime.InteropServices.Marshal.FinalReleaseComObject(ExcelApp);
  }

  throw;
}
finally
{

}

前几天我还在和这个抗争

尝试使用以下方法:

Process.Start("EXCEL.EXE", "\" " + FileLocation+ " \"");

查看参数中的“\”是否有空格。

您看到了什么错误消息/异常?在哪一行代码?
Process.Start(“C:\temp\test.xlsx”)如果安装了Excel,则打开xlsx文件。如果没有安装,我不知道。