namespace Get_RangeTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Excel.Application ExcelApp = new Excel.Application();
//エクセルを非表示
ExcelApp.Visible = false;
//エクセルファイルのオープン
Excel.Workbook WorkBook = ExcelApp.Workbooks.Open("C:\\test\\test.xlsx");
//1シート目の選択
Excel.Worksheet sheet = WorkBook.Sheets[1];
sheet.Select();
//A1セルのデータの取得
Excel.Range range = sheet.get_Range("Sheet1_Range");
if (range != null)
{
string[,] arry = new string[10, 1];
arry[0, 0] = "1test";
arry[1, 0] = "2test";
arry[2, 0] = "3test";
arry[3, 0] = "4test";
arry[4, 0] = "5test";
arry[5, 0] = "6test";
arry[6, 0] = "7test";
arry[7, 0] = "8test";
arry[8, 0] = "9test";
arry[9, 0] = "10test";
//double[][] a = new double[][]{
// new double[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
// new double[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
// new double[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
//};
//var tmp = a.SelectMany(
// x => x.Select((item, index) => new { item, index }))
// .GroupBy(y => y.index, (key, z) => { return z.Average(n => n.item); }
);
range.Value2 = arry;
}
WorkBook.Save();
//workbookを閉じる
WorkBook.Close();
//エクセルを閉じる
ExcelApp.Quit();
}