一時フォルダーから Excel シートを開くためのコードを使用しています。
ファイルを開くために2つのオプションを使用しています。最初に を使用しています。process.start()
これがエラーをスローしている場合は、 を使用して 2 番目のものを使用しinterop services
ます。しかし、どちらもExcel 2013(365)を搭載したWin 8 PCでエラーをスローしています。
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
{
}