| 分類:[C# (Windows)]
初めて投稿させて頂きます。
COMオブジェクトを使用して、EXCELを出力している機能で、 OSがXPの場合、正常に動作するのですが、Win2000(SP4)の場合、
HRESULTからの例外です:0x800A03EC。
というエラーが発生します。
使用しているライブラリはMicrosoft Excel 9.0 Object Libraryです。
ソースを下記に添付致します。 宜しくお願い致します。
Excel.Application xlApplication = null; Excel.Workbooks xlWorkbooks = null; Excel._Workbook xlWorkbook = null; Excel.Sheets xlSheets = null; Excel._Worksheet xlWorkSheet = null; Excel.Range xlRange = null; // Excel作成 try { // 新しいbookを作る try { xlApplication = new Excel.Application(); // Excelアプリケーション xlApplication.DisplayAlerts = false;
try { xlWorkbooks = xlApplication.Workbooks;
try { xlWorkbook = null;
if (rdo_Syain.Checked == true) { xlWorkbook = xlWorkbooks.Add(CMArea.NEXTUserFileTemplatePath); } else if (rdo_Sosiki.Checked == true) { xlWorkbook = xlWorkbooks.Add(CMArea.NEXTGroupFileTemplatePath); } else if (rdo_Yaku.Checked == true) { xlWorkbook = xlWorkbooks.Add(CMArea.NEXTPostFileTemplatePath); }
try { xlSheets = xlWorkbook.Worksheets;
try { xlWorkSheet = (Excel._Worksheet)xlSheets.get_Item(1); xlRange = null;
try { // 範囲を獲得 long lRowCnt = insData.GetLength(0); long lColCnt = insData.GetLength(1); xlRange = xlWorkSheet.get_Range("A3", Type.Missing); xlRange = xlRange.get_Resize(lRowCnt, lColCnt);
// 値を代入 xlRange.Value = insData;
//保存 xlWorkbook.SaveAs(txt_FilePath1.Text, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } finally { if (xlRange != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange); //COM オブジェクト解放 } } finally { if (xlWorkSheet != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkSheet); //COM オブジェクト解放 } } finally { if (xlSheets != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets); //COM オブジェクト解放 } } finally { try { xlWorkbook.Close(Missing.Value, Missing.Value, Missing.Value); } finally { if (xlWorkbook != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkbook); //COM オブジェクト解放 } } } finally { try { xlWorkbooks.Close(); } finally { if (xlWorkbooks != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkbooks); //COM オブジェクト解放 } } } finally { try { // Excel を終了する xlApplication.Quit(); } finally { if (xlApplication != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApplication); //COM オブジェクト解放 }
} bRtn = true; } catch (Exception exc) { MessageBox.Show("Excel作成時にエラーが発生しました。\n\n" + exc.Message , lbl_Title.Text , MessageBoxButtons.OK, MessageBoxIcon.Error); bRtn = false; } |