使用interop服务和process.start()从c#win表单打开excel文件时出错
我正在使用代码从临时文件夹打开excel工作表 我使用2个选项打开一个文件。 首先,我使用的是使用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.
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文件。如果没有安装,我不知道。