-1

一時フォルダーから 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
{

}
4

1 に答える 1

0

私は数日前にこれと戦っていました。

これを使用してみてください:

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

「\」のパラメータに空白があることを確認してください。

于 2013-05-24T12:20:26.150 に答える