C#によるExcel出力について

Excel出力のサンプルソース

using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Data.SQLite;
using System.Data;
using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;

namespace ConsoleApplication
{
    public class SampleExcel
    {
        static void Main(string[] args)
        {
            Excel.Application oXlsApp = null;
            Excel.Workbook oBook = null;
            Excel.Worksheet oSheet = null;
            Excel.Range oRange = null;
            object missing = System.Reflection.Missing.Value;
            FileInfo exePath
            = new FileInfo(Environment.CommandLine.Replace( "\"", "" ));
            string exeDir = exePath.Directory.ToString();
            // エクセル起動
            try
            {
                oXlsApp = new Excel.Application();
                // エクセル非表示
                oXlsApp.Application.Visible = false;
                oXlsApp.Application.DisplayAlerts = false;
                // ブック追加
                oBook = oXlsApp.Application.Workbooks.Add(Type.Missing);
                // シート選択
                oSheet = (Excel.Worksheet)oXlsApp.Worksheets[1];
                oSheet.Name = "シート名前変更";
                // セルに値設定
                oRange = oSheet.get_Range(oSheet.Cells[3, 3], oSheet.Cells[3, 3]);
                oRange.Value2 = "1";
                oRange = oSheet.get_Range(oSheet.Cells[3, 4], oSheet.Cells[3, 4]);
                oRange.Value2 = "2";
                // 名前を付けて保存する
                oBook.SaveAs(System.IO.Path.Combine(exeDir,"試験.xls"),
                    Excel.XlFileFormat.xlWorkbookNormal, missing, missing,
                    false, false, Excel.XlSaveAsAccessMode.xlNoChange,
                    missing, missing, missing, missing, missing);
            }
            finally
            {
                // エクセルを閉じる
                if (oBook != null) oBook.Close(false, missing, missing);
                if (oXlsApp != null) oXlsApp.Quit();
                oRange = null;
                oSheet = null;
                oBook = null;
                oXlsApp = null;
            }
        }
    }
}

inserted by FC2 system