EXCELのファイルオープン処理

EXCELのファイルオープン処理
前提条件:using Excel = Microsoft.Office.Interop.Excel;
(※上記usingでエラーが表示される場合は、参照設定されていないか、既に「Excel」という名前空間が存在している状態となります)

//ファイル名
string excelName = "C:\\sample.xls";

 // Excelインスタンス
Excel.Application oXls 
 = new Excel.Application();

// 確認のためExcelのウィンドウを表示する
oXls.Visible = true; 

// Excelファイルをオープンする
Excel.Workbook oWBook   =  (Excel.Workbook)(oXls.Workbooks.Open(
      excelName,  // オープンするExcelファイル名
     Type.Missing, // (省略可能)UpdateLinks (0 / 1 / 2 / 3)
     Type.Missing, // (省略可能)ReadOnly (True / False )
     Type.Missing, // (省略可能)Format
      // 1:タブ / 2:カンマ (,) / 3:スペース / 4:セミコロン (;)
      // 5:なし / 6:引数 Delimiterで指定された文字
      Type.Missing, // (省略可能)Password
      Type.Missing, // (省略可能)WriteResPassword
      Type.Missing, // (省略可能)IgnoreReadOnlyRecommended
      Type.Missing, // (省略可能)Origin
       Type.Missing, // (省略可能)Delimiter
       Type.Missing, // (省略可能)Editable
       Type.Missing, // (省略可能)Notify
       Type.Missing, // (省略可能)Converter
       Type.Missing, // (省略可能)AddToMru
       Type.Missing, // (省略可能)Local
       Type.Missing  // (省略可能)CorruptLoad
));

コメント