VSTO (Visual Studio Tools for Office) のダウンロードを開始すると、C# Excel アドインを作成できるようになります。
Visual Studio で新しいプロジェクトを作成すると、Office が表示され、そこから Excel を選択できるようになります。
そこから始めて、それができたら、戻ってきて、より具体的な質問をすることができます.
Excel での作業に役立つヒント。
アクティブなシートを選択するには:
Excel.Worksheet sheet = this.Application.ActiveSheet as Excel.Worksheet;
特定の範囲 (この場合は A1 ~ B5) を選択するには:
Excel.Range range = sheet.get_Range("A1", "B5") as Excel.Range;
範囲全体に値を設定するには:
range.Value2 = 2; //will set every cell in A1 through B5 to 2
たとえば、次のように、2 次元配列の範囲から値を取得できます。
object[,] values = range.Value2 as object[,];
//this will return an multidimensional array representing rows and cols
//as you see in the range. in this case the array is filed with "2"
次に、配列全体の値を変更して、範囲に適用し直すことができます。
values[2, 2] = 4; //will change the value to 4 in row 2, col 2 of the *range*
range.Value2 = values; //set back the whole range to the array
この手法を使用して、最初に配列を準備し、次にそれを範囲値に設定することで、範囲全体を一度に更新できます。
範囲内の特定のセルから値を取得するには(値を設定するには同じ方法ですが、逆になります)。
Excel.Range cell = range.Cells[1,1] as Excel.Range; //this will take the cell from row 1, cell 1. if you used array this would be values[1,1]
string value = (cell.Value2 ?? "").ToString();
これにより、Excel で基本的なタスクを実行できるようになります。値を設定したり、値を取得したり、範囲を選択したりできます。より具体的な質問がありましたら、戻ってきてください。
Excel からの配列はゼロベースではなく 1 ベースであることを忘れないでください!!!