2011年2月26日土曜日

エクセルにすべて出力

Microsoft::Office::Interop::Excel::Application^ ap1 = gcnew Microsoft::Office::Interop::Excel::ApplicationClass();

//ヘッダーテキストをエクセルに送る
for(int i = 1; i < dataGridView1->Columns->Count + 1 ; i++){
   ap1->Cells[1,i] = dataGridView1->Columns[i-1]->HeaderText;
}

//行と列をエクセルに送る
for( int i = 0 ; i < (dataGridView1->Rows->Count-1) ; i++ ){
   for( int j = 0 ; j < (dataGridView1->Columns->Count) ; j++ ){    
   ap1->Cells[i + 2 , j + 1] = dataGridView1->Rows[i]->Cells[j]->Value->ToString();
   }
}

ap1->Visible = true;

0 件のコメント:

コメントを投稿