<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C#でExcelを読み込んで操作する方法を公開｜C# Excel操作テクニック.NET</title>
	<atom:link href="http://excelcsharp.lance40.com/feed" rel="self" type="application/rss+xml" />
	<link>http://excelcsharp.lance40.com</link>
	<description>メソッドに貼り付けるだけで機能するソースコードを多数用意しています。</description>
	<lastBuildDate>Sun, 08 Nov 2015 04:41:39 +0000</lastBuildDate>
	<language>ja</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.7.41</generator>
	<item>
		<title>二次元配列をセルに一括出力する</title>
		<link>http://excelcsharp.lance40.com/post-4.html</link>
		<comments>http://excelcsharp.lance40.com/post-4.html#comments</comments>
		<pubDate>Sat, 07 Nov 2015 17:07:37 +0000</pubDate>
		<dc:creator><![CDATA[Janga]]></dc:creator>
				<category><![CDATA[セル操作]]></category>
		<category><![CDATA[プロパティ]]></category>

		<guid isPermaLink="false">http://excelcsharp.lance40.com/?p=230</guid>
		<description><![CDATA[二次元配列の値をそのままセルに一括出力する方法です。 二次元配列の各要素が１つのセルに設定されます。 以下の処理では、適当な二次元配列を作成後、指定したセルの範囲に値を出力しています。]]></description>
				<content:encoded><![CDATA[<p>二次元配列の値をそのままセルに一括出力する方法です。</p>
<p>二次元配列の各要素が１つのセルに設定されます。</p>
<p>以下の処理では、適当な二次元配列を作成後、指定したセルの範囲に値を出力しています。</p>
<pre class="brush: csharp; title: ; notranslate">

            #region &quot;work 貼り付ける値を作成&quot;

            // 10行4列イメージの二次元配列
            object[,] setValue = new object[9, 4];

            for (int i = 0; i &lt; 9; i++)
            {
                for (int j = 0; j &lt; 4; j++)
                {
                    setValue[i, j] = string.Format(&quot;{0}行{1}列目&quot;, i + 1, j + 1);
                }
            }

            #endregion


            // Excel操作用オブジェクト
            Microsoft.Office.Interop.Excel.Application xlApp = null;
            Microsoft.Office.Interop.Excel.Workbooks xlBooks = null;
            Microsoft.Office.Interop.Excel.Workbook xlBook = null;
            Microsoft.Office.Interop.Excel.Sheets xlSheets = null;
            Microsoft.Office.Interop.Excel.Worksheet xlSheet = null;

            // Excelアプリケーション生成
            xlApp = new Microsoft.Office.Interop.Excel.Application();

            // 既存のBookを開く
            xlBooks = xlApp.Workbooks;
            xlBook = xlBooks.Open(System.IO.Path.GetFullPath(@&quot;..\..\..\data\work01.xlsx&quot;));

            // シートを選択する
            xlSheets = xlBook.Worksheets;
            // 1シート目を操作対象に設定する
            // ※Worksheets[n]はオブジェクト型を返すため、Worksheet型にキャスト
            xlSheet = xlSheets[1] as Microsoft.Office.Interop.Excel.Worksheet;

            // 表示
            xlApp.Visible = true;

            int iColCnt = 0;    //列数カウンタ
            int iRowCnt = 0;    //行数カウンタ
            Microsoft.Office.Interop.Excel.Range xlCellsFrom = null;   //セル始点（中継用）
            Microsoft.Office.Interop.Excel.Range xlRangeFrom = null;   //セル始点
            Microsoft.Office.Interop.Excel.Range xlCellsTo = null;     //セル終点（中継用）
            Microsoft.Office.Interop.Excel.Range xlRangeTo = null;     //セル終点   
            Microsoft.Office.Interop.Excel.Range xlTarget = null;      //配列設定対象レンジ

            //配列の要素数取得
            iRowCnt = setValue.GetLength(0) - 1;
            iColCnt = setValue.GetLength(1) - 1;

            // 貼り付け位置
            int col = 4;
            int row = 5;

            //始点セル取得
            xlCellsFrom = xlSheet.Cells;
            xlRangeFrom = xlCellsFrom[row, col] as Microsoft.Office.Interop.Excel.Range;

            //終点セル取得
            xlCellsTo = xlSheet.Cells;
            xlRangeTo = xlCellsTo[row + iRowCnt, col + iColCnt] as Microsoft.Office.Interop.Excel.Range;

            //貼り付け対象レンジ
            xlTarget = xlSheet.Range[xlRangeFrom, xlRangeTo];

            //◆値設定◆
            xlTarget.Value = setValue;

            // ■■■以下、COMオブジェクトの解放■■■

            // cell解放
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlTarget);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRangeTo);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlCellsTo);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRangeFrom);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlCellsFrom);

            // Sheet解放
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets);

            // Book解放
            //xlBook.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks);

            // Excelアプリケーションを解放
            //xlApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);



</pre>
]]></content:encoded>
			<wfw:commentRss>http://excelcsharp.lance40.com/post-4.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>セルの値を取得／設定する</title>
		<link>http://excelcsharp.lance40.com/post-3.html</link>
		<comments>http://excelcsharp.lance40.com/post-3.html#comments</comments>
		<pubDate>Sat, 07 Nov 2015 17:04:15 +0000</pubDate>
		<dc:creator><![CDATA[Janga]]></dc:creator>
				<category><![CDATA[セル操作]]></category>
		<category><![CDATA[プロパティ]]></category>

		<guid isPermaLink="false">http://excelcsharp.lance40.com/?p=228</guid>
		<description><![CDATA[指定したセルの値を取得／設定します。 以下の処理は、行列番号でセルを指定し、そのセルに任意の値を設定し、入力された値を取得しています。]]></description>
				<content:encoded><![CDATA[<p>指定したセルの値を取得／設定します。</p>
<p>以下の処理は、行列番号でセルを指定し、そのセルに任意の値を設定し、入力された値を取得しています。</p>
<pre class="brush: csharp; title: ; notranslate">

            // Excel操作用オブジェクト
            Microsoft.Office.Interop.Excel.Application xlApp = null;
            Microsoft.Office.Interop.Excel.Workbooks xlBooks = null;
            Microsoft.Office.Interop.Excel.Workbook xlBook = null;
            Microsoft.Office.Interop.Excel.Sheets xlSheets = null;
            Microsoft.Office.Interop.Excel.Worksheet xlSheet = null;

            // Excelアプリケーション生成
            xlApp = new Microsoft.Office.Interop.Excel.Application();

            // 既存のBookを開く
            xlBooks = xlApp.Workbooks;
            xlBook = xlBooks.Open(System.IO.Path.GetFullPath(@&quot;..\..\..\data\work01.xlsx&quot;));

            // シートを選択する
            xlSheets = xlBook.Worksheets;
            // 1シート目を操作対象に設定する
            // ※Worksheets[n]はオブジェクト型を返すため、Worksheet型にキャスト
            xlSheet = xlSheets[1] as Microsoft.Office.Interop.Excel.Worksheet;

            // 表示
            xlApp.Visible = true;

            // セルのオブジェクト
            Microsoft.Office.Interop.Excel.Range xlRange = null;
            Microsoft.Office.Interop.Excel.Range xlCells = null;

            // B3セルを指定
            xlCells = xlSheet.Cells;
            xlRange = xlCells[3, 2] as Microsoft.Office.Interop.Excel.Range;

            // ◆現在の値を表示◆
            MessageBox.Show(xlRange.Value);

            // ◆値を設定◆
            xlRange.Value = &quot;変更後の値&quot;;

            // 変更後の値を表示
            MessageBox.Show(xlRange.Value);

            // ■■■以下、COMオブジェクトの解放■■■

            // cell解放
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRange);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlCells);

            // Sheet解放
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets);

            // Book解放
            //xlBook.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks);

            // Excelアプリケーションを解放
            //xlApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);


</pre>
]]></content:encoded>
			<wfw:commentRss>http://excelcsharp.lance40.com/post-3.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excelを開いたまま処理を終了させる</title>
		<link>http://excelcsharp.lance40.com/post-2.html</link>
		<comments>http://excelcsharp.lance40.com/post-2.html#comments</comments>
		<pubDate>Sat, 07 Nov 2015 16:56:19 +0000</pubDate>
		<dc:creator><![CDATA[Janga]]></dc:creator>
				<category><![CDATA[ブック操作]]></category>
		<category><![CDATA[COM解放のみ]]></category>
		<category><![CDATA[Excel開いたまま]]></category>

		<guid isPermaLink="false">http://excelcsharp.lance40.com/?p=222</guid>
		<description><![CDATA[Excelが開いた状態でメソッドやアプリを終了しても、プロセスが残らないコードです。 以下の処理を実行すると、Excelの新規Bookが1つ起動します。 処理自体は最後まで流れますが、表示したExcelは開いたままになっ [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Excelが開いた状態でメソッドやアプリを終了しても、プロセスが残らないコードです。</p>
<p>以下の処理を実行すると、Excelの新規Bookが1つ起動します。</p>
<p>処理自体は最後まで流れますが、表示したExcelは開いたままになっており、マウス操作でExcelを閉じてもタスクマネージャにプロセスは残りません。</p>
<p>ポイントは、処理の最後でExcelの終了処理（BOOKやApplicationクラスの終了処理）を行わず、COMオブジェクトの解放のみを行う点です。</p>
<pre class="brush: csharp; title: ; notranslate">

            // Excel操作用オブジェクト
            Microsoft.Office.Interop.Excel.Application xlApp = null;
            Microsoft.Office.Interop.Excel.Workbooks xlBooks = null;
            Microsoft.Office.Interop.Excel.Workbook xlBook = null;
            Microsoft.Office.Interop.Excel.Sheets xlSheets = null;
            Microsoft.Office.Interop.Excel.Worksheet xlSheet = null;

            // Excelアプリケーション生成
            xlApp = new Microsoft.Office.Interop.Excel.Application();

            // 新規のExcelブックを開く
            // Addメソッド
            xlBooks = xlApp.Workbooks;
            xlBook = xlBooks.Add();

            // シートを選択する
            xlSheets = xlBook.Worksheets;
            xlSheet = xlSheets[1] as Microsoft.Office.Interop.Excel.Worksheet; // 1シート目を操作対象に設定する

            // 表示
            xlApp.Visible = true;

            // ■■■以下、COMオブジェクトの解放■■■

            // Sheet解放
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets);

            // ◆プロセスが残らないようにメソッドを抜けるには、
            // 　★の部分をコメントアウトする

            // Book解放
            //xlBook.Close(); //★
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks);

            // Excelアプリケーションを解放
            //xlApp.Quit(); //★
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);


</pre>
]]></content:encoded>
			<wfw:commentRss>http://excelcsharp.lance40.com/post-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>複数シートを選択する</title>
		<link>http://excelcsharp.lance40.com/post.html</link>
		<comments>http://excelcsharp.lance40.com/post.html#comments</comments>
		<pubDate>Sun, 23 Feb 2014 12:44:24 +0000</pubDate>
		<dc:creator><![CDATA[Janga]]></dc:creator>
				<category><![CDATA[シート操作]]></category>
		<category><![CDATA[メソッド]]></category>
		<category><![CDATA[Selectメソッド引数]]></category>
		<category><![CDATA[シート選択]]></category>
		<category><![CDATA[複数シート]]></category>

		<guid isPermaLink="false">http://excelcsharp.lance40.com/?p=166</guid>
		<description><![CDATA[複数シートを選択状態にするコードです。 注意点は、_Worksheet.Selectメソッドの引数です。 ループ処理で対象シートを選択していますが、最初のループのみ引数にはTrueを設定し、以降のシート選択時はFalse [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>複数シートを選択状態にするコードです。</p>
<p>注意点は、_Worksheet.Selectメソッドの引数です。</p>
<p>ループ処理で対象シートを選択していますが、最初のループのみ引数にはTrueを設定し、以降のシート選択時はFalseを設定しています。</p>
<p>この引数は、「すでに選択しているシートを選択解除するかどうか」の判定です。</p>
<pre class="brush: csharp; title: ; notranslate">
        {
            // Excel操作用オブジェクト
            Microsoft.Office.Interop.Excel.Application xlApp = null;
            Microsoft.Office.Interop.Excel.Workbooks xlBooks = null;
            Microsoft.Office.Interop.Excel.Workbook xlBook = null;
            Microsoft.Office.Interop.Excel.Sheets xlSheets = null;
            Microsoft.Office.Interop.Excel.Worksheet xlSheet = null;

            // Excelアプリケーション生成
            xlApp = new Microsoft.Office.Interop.Excel.Application();

            // 既存のBookを開く
            xlBooks = xlApp.Workbooks;
            xlBook = xlBooks.Open(System.IO.Path.GetFullPath(@&quot;..\..\..\data\work01.xlsx&quot;));

            // シートを取得する
            xlSheets = xlBook.Worksheets;

            // 1シート目を操作対象に設定する
            // 作業用変数
            int i = 0;              // ループカウンタ
            bool bActivate = true;  // シート選択時の引数

            // ◆Sheet1とSheet2を選択状態にする◆
            // (Sheet1がアクティブ状態)
            while (i &lt; 2)
            {
                // 2シート目以降はFalseを設定
                if (i &gt; 0)
                    bActivate = false;

                i = i + 1;

                // ※Worksheets[n]はオブジェクト型を返すため、Worksheet型にキャスト
                xlSheet = xlSheets[i] as Microsoft.Office.Interop.Excel.Worksheet;

                // iシート目を選択状態に設定
                xlSheet.Select(bActivate);

                // シートオブジェクト解放
                System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);

            }

            // 表示
            xlApp.Visible = true;

            // ■■■以下、COMオブジェクトの解放■■■

            // Sheet解放
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets);

            // Book解放
            //xlBook.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks);

            // Excelアプリケーションを解放
            //xlApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
        }

</pre>
]]></content:encoded>
			<wfw:commentRss>http://excelcsharp.lance40.com/post.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sheetの名称を取得・設定する</title>
		<link>http://excelcsharp.lance40.com/sheetname.html</link>
		<comments>http://excelcsharp.lance40.com/sheetname.html#comments</comments>
		<pubDate>Fri, 29 Nov 2013 13:11:51 +0000</pubDate>
		<dc:creator><![CDATA[Janga]]></dc:creator>
				<category><![CDATA[シート操作]]></category>
		<category><![CDATA[プロパティ]]></category>
		<category><![CDATA[シート名取得]]></category>
		<category><![CDATA[シート名変更]]></category>

		<guid isPermaLink="false">http://excelcsharp.lance40.com/?p=164</guid>
		<description><![CDATA[操作中Sheetの名称を取得・設定します。 注意点は、Sheet[n]をWorkSheetオブジェクトに設定する際はキャストが必要だということです。]]></description>
				<content:encoded><![CDATA[<p>操作中Sheetの名称を取得・設定します。</p>
<p>注意点は、Sheet[n]をWorkSheetオブジェクトに設定する際はキャストが必要だということです。</p>
<pre class="brush: csharp; title: ; notranslate">
        {
            // Excel操作用オブジェクト
            Microsoft.Office.Interop.Excel.Application xlApp = null;
            Microsoft.Office.Interop.Excel.Workbooks xlBooks = null;
            Microsoft.Office.Interop.Excel.Workbook xlBook = null;
            Microsoft.Office.Interop.Excel.Sheets xlSheets = null;
            Microsoft.Office.Interop.Excel.Worksheet xlSheet = null;

            // Excelアプリケーション生成
            xlApp = new Microsoft.Office.Interop.Excel.Application();

            // 新規のExcelブックを開く
            xlBooks = xlApp.Workbooks;
            xlBook = xlBooks.Add();

            // シートを選択する
            xlSheets = xlBook.Worksheets;
            // 1シート目を操作対象に設定する
            // ※Worksheets[n]はオブジェクト型を返すため、Worksheet型にキャスト
            xlSheet = xlSheets[1] as Microsoft.Office.Interop.Excel.Worksheet;

            // 表示
            xlApp.Visible = true;

            // Sheet名表示
            MessageBox.Show(xlSheet.Name);

            // ◆シート1の名称を変更する◆
            // Nameプロパティ
            xlSheet.Name = &quot;Sheet999&quot;;

            // Sheet名表示
            MessageBox.Show(xlSheet.Name);


            // ■■■以下、COMオブジェクトの解放■■■

            // Sheet解放
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets);

            // Book解放
            //xlBook.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks);

            // Excelアプリケーションを解放
            //xlApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);

        }

</pre>
]]></content:encoded>
			<wfw:commentRss>http://excelcsharp.lance40.com/sheetname.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excelアプリケーション(Excel.exe)のパスを取得する</title>
		<link>http://excelcsharp.lance40.com/excelpath.html</link>
		<comments>http://excelcsharp.lance40.com/excelpath.html#comments</comments>
		<pubDate>Fri, 29 Nov 2013 12:34:25 +0000</pubDate>
		<dc:creator><![CDATA[Janga]]></dc:creator>
				<category><![CDATA[Excelｱﾌﾟﾘｹｰｼｮﾝ操作]]></category>
		<category><![CDATA[プロパティ]]></category>
		<category><![CDATA[exeパス]]></category>
		<category><![CDATA[フルパス]]></category>

		<guid isPermaLink="false">http://excelcsharp.lance40.com/?p=158</guid>
		<description><![CDATA[Excel.exeのフォルダの完全パスを取得します。 ※操作中のファイルパスではありません、注意してください。 （32bit OSでのデフォルトはC:\Program Files\Microsoft Office…あたり [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Excel.exeのフォルダの完全パスを取得します。</p>
<p>※操作中のファイルパスではありません、注意してください。</p>
<p>（32bit OSでのデフォルトはC:\Program Files\Microsoft Office…あたりだと思います。）</p>
<pre class="brush: csharp; title: ; notranslate">
{
            // Excel操作用オブジェクト
            Microsoft.Office.Interop.Excel.Application xlApp = null;
            

            // Excelアプリケーション生成
            xlApp = new Microsoft.Office.Interop.Excel.Application();

            // ◆Exe格納パスをメッセージボックスに表示◆
            // Pathプロパティ
            System.Windows.Forms.MessageBox.Show(xlApp.Path);

            // Excelアプリケーションを解放
            xlApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);

 }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://excelcsharp.lance40.com/excelpath.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ExcelのSheet数を取得する</title>
		<link>http://excelcsharp.lance40.com/sheetcnt.html</link>
		<comments>http://excelcsharp.lance40.com/sheetcnt.html#comments</comments>
		<pubDate>Fri, 29 Nov 2013 12:23:14 +0000</pubDate>
		<dc:creator><![CDATA[Janga]]></dc:creator>
				<category><![CDATA[シート操作]]></category>
		<category><![CDATA[プロパティ]]></category>
		<category><![CDATA[Countプロパティ]]></category>
		<category><![CDATA[シート数取得]]></category>

		<guid isPermaLink="false">http://excelcsharp.lance40.com/?p=147</guid>
		<description><![CDATA[操作対象Excelのシート数を取得します。]]></description>
				<content:encoded><![CDATA[<p>操作対象Excelのシート数を取得します。</p>
<pre class="brush: csharp; title: ; notranslate">
        {
            // Excel操作用オブジェクト
            Microsoft.Office.Interop.Excel.Application xlApp = null;
            Microsoft.Office.Interop.Excel.Workbooks xlBooks = null;
            Microsoft.Office.Interop.Excel.Workbook xlBook = null;
            Microsoft.Office.Interop.Excel.Sheets xlSheets = null;

            // Excelアプリケーション生成
            xlApp = new Microsoft.Office.Interop.Excel.Application();

            // 既存のBookを開く
            xlBooks = xlApp.Workbooks;
            xlBook = xlBooks.Open(System.IO.Path.GetFullPath(@&quot;..\..\..\data\work01.xlsx&quot;));

            // シートを取得する
            xlSheets = xlBook.Worksheets;

            // 表示
            xlApp.Visible = true;

            // ◆シート数取得◆
            // Countプロパティ
            System.Windows.Forms.MessageBox.Show(xlSheets.Count.ToString());

            // ■■■以下、COMオブジェクトの解放■■■

            // Sheet解放
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets);

            // Book解放
            //xlBook.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks);

            // Excelアプリケーションを解放
            //xlApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);


        }

</pre>
]]></content:encoded>
			<wfw:commentRss>http://excelcsharp.lance40.com/sheetcnt.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ExcelBook、アプリケーションを閉じる</title>
		<link>http://excelcsharp.lance40.com/closeapp.html</link>
		<comments>http://excelcsharp.lance40.com/closeapp.html#comments</comments>
		<pubDate>Sun, 24 Nov 2013 12:05:51 +0000</pubDate>
		<dc:creator><![CDATA[Janga]]></dc:creator>
				<category><![CDATA[Excelｱﾌﾟﾘｹｰｼｮﾝ操作]]></category>
		<category><![CDATA[ブック操作]]></category>
		<category><![CDATA[メソッド]]></category>
		<category><![CDATA[Closeメソッド]]></category>
		<category><![CDATA[Excel閉じる]]></category>
		<category><![CDATA[Quitメソッド]]></category>
		<category><![CDATA[ブック閉じる]]></category>

		<guid isPermaLink="false">http://excelcsharp.lance40.com/?p=144</guid>
		<description><![CDATA[Excelを閉じる処理です。 「◆Bookを閉じる◆」で、WorkBookを閉じる処理を行い、 「◆Excelアプリケーション閉じる◆」で、アプリケーションの終了処理を行っています。]]></description>
				<content:encoded><![CDATA[<p>Excelを閉じる処理です。</p>
<p>「◆Bookを閉じる◆」で、WorkBookを閉じる処理を行い、<br />
「◆Excelアプリケーション閉じる◆」で、アプリケーションの終了処理を行っています。</p>
<pre class="brush: csharp; title: ; notranslate">
{
    // Excel操作用オブジェクト
    Application xlApp = null;
    Workbooks xlBooks = null;
    Workbook xlBook = null;
    Sheets xlSheets = null;
    Worksheet xlSheet = null;

    // Excelアプリケーション生成
    xlApp = new Application();
    xlApp.DisplayAlerts = false;    // 確認メッセージを非表示に設定

    // 新規のExcelブックを開く
    xlBooks = xlApp.Workbooks;
    xlBook = xlBooks.Add();

    // シートを選択する
    xlSheets = xlBook.Worksheets;
    xlSheet = xlSheets[1] as Worksheet; // 1シート目を操作対象に設定する

    // 確認のためExcelを表示させて3秒停止
    xlApp.Visible = true;
    System.Threading.Thread.Sleep(3000);

    // ■■■以下、COMオブジェクトの解放■■■

    // Sheet解放
    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets);

    // ◆Bookを閉じる◆
    // Closeメソッド
    xlBook.Close();
    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks);

    // アラートを元に戻す
    xlApp.DisplayAlerts = true;

    // ◆Excelアプリケーション閉じる◆
    // Quitメソッド
    xlApp.Quit();
    System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://excelcsharp.lance40.com/closeapp.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excelの確認メッセージを非表示に設定する（アラート設定）</title>
		<link>http://excelcsharp.lance40.com/displayalerts.html</link>
		<comments>http://excelcsharp.lance40.com/displayalerts.html#comments</comments>
		<pubDate>Sun, 24 Nov 2013 11:51:25 +0000</pubDate>
		<dc:creator><![CDATA[Janga]]></dc:creator>
				<category><![CDATA[Excelｱﾌﾟﾘｹｰｼｮﾝ操作]]></category>
		<category><![CDATA[プロパティ]]></category>
		<category><![CDATA[DisplayAlertsプロパティ]]></category>
		<category><![CDATA[アラート]]></category>
		<category><![CDATA[メッセージ非表示]]></category>

		<guid isPermaLink="false">http://excelcsharp.lance40.com/?p=141</guid>
		<description><![CDATA[操作対象のExcelアプリケーションのDisplayAlertsプロパティを取得・設定します。 DisplayAlertsにFalseを設定すると、Excelを閉じるときなどに表示されるメッセージの表示／非表示を制御でき [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>操作対象のExcelアプリケーションのDisplayAlertsプロパティを取得・設定します。</p>
<p>DisplayAlertsにFalseを設定すると、Excelを閉じるときなどに表示されるメッセージの表示／非表示を制御できます。</p>
<p>以下の処理を実行すると、表示されたExcelの編集→閉じる操作をしても保存要否の確認メッセージが表示されません。</p>
<p>逆に<strong>xlApp.DisplayAlerts</strong>にTrueを設定すると、確認メッセージが表示されるようになります。</p>
<pre class="brush: csharp; title: ; notranslate">
        {

            // Excel操作用オブジェクト
            Microsoft.Office.Interop.Excel.Application xlApp = null;
            Microsoft.Office.Interop.Excel.Workbooks xlBooks = null;
            Microsoft.Office.Interop.Excel.Workbook xlBook = null;
            Microsoft.Office.Interop.Excel.Sheets xlSheets = null;
            Microsoft.Office.Interop.Excel.Worksheet xlSheet = null;

            // Excelアプリケーション生成
            xlApp = new Microsoft.Office.Interop.Excel.Application();

            // ◆アラートメッセージ非表示設定◆
            xlApp.DisplayAlerts = false;

            // 新規のExcelブックを開く
            // Addメソッド
            xlBooks = xlApp.Workbooks;
            xlBook = xlBooks.Add();

            // シートを選択する
            xlSheets = xlBook.Worksheets;
            xlSheet = xlSheets[1] as Microsoft.Office.Interop.Excel.Worksheet; // 1シート目を操作対象に設定する

            // 表示
            xlApp.Visible = true;

            // ■■■以下、COMオブジェクトの解放■■■

            // Sheet解放
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets);

            // Book解放
            //xlBook.Close();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks);

            // Excelアプリケーションを解放
            //xlApp.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);


        }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://excelcsharp.lance40.com/displayalerts.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excelのバージョンを取得する</title>
		<link>http://excelcsharp.lance40.com/version.html</link>
		<comments>http://excelcsharp.lance40.com/version.html#comments</comments>
		<pubDate>Wed, 20 Nov 2013 14:32:31 +0000</pubDate>
		<dc:creator><![CDATA[Janga]]></dc:creator>
				<category><![CDATA[Excelｱﾌﾟﾘｹｰｼｮﾝ操作]]></category>
		<category><![CDATA[プロパティ]]></category>
		<category><![CDATA[バージョン]]></category>

		<guid isPermaLink="false">http://excelcsharp.lance40.com/?p=108</guid>
		<description><![CDATA[Excelのバージョンを取得します。 このプロパティによって取得できる値は以下の通りです。 &#160; Excel バージョン 2010 14.0 2007 12.0 2003 11.0 2002 10.0 2000  [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Excelのバージョンを取得します。</p>
<p>このプロパティによって取得できる値は以下の通りです。</p>
<p>&nbsp;</p>
<table border="2" cellpadding="5">
<tbody>
<tr>
<td><strong>Excel</strong></td>
<td><strong>バージョン</strong></td>
</tr>
<tr>
<td>2010</td>
<td>14.0</td>
</tr>
<tr>
<td>2007</td>
<td>12.0</td>
</tr>
<tr>
<td>2003</td>
<td>11.0</td>
</tr>
<tr>
<td>2002</td>
<td>10.0</td>
</tr>
<tr>
<td>2000</td>
<td>9.0</td>
</tr>
<tr>
<td>97</td>
<td>8.0</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>取得方法は以下のようになります。</p>
<pre class="brush: csharp; title: ; notranslate">

 {

     // Excel操作用オブジェクト
     Application xlApp = null;

     // Excelアプリケーション生成
     xlApp = new Application();

     // ◆バージョン番号をメッセージボックスに表示◆
     // Versionプロパティ
     System.Windows.Forms.MessageBox.Show(xlApp.Version);

     // Excelアプリケーションを解放
     xlApp.Quit();
     System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);

 }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://excelcsharp.lance40.com/version.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
