我正在使用代码从临时文件夹中打开一个 excel 表。
我正在使用 2 个选项来打开文件。首先我正在使用process.start()
,如果这引发错误,我将使用第二个使用interop services
. 但两者都在带有 excel 2013 (365) 的 Win 8 电脑上抛出错误。
请帮助4这个。
代码是
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
{
}