2011年2月26日土曜日

エクセルにすべて出力

  1. Microsoft::Office::Interop::Excel::Application^ ap1 = gcnew Microsoft::Office::Interop::Excel::ApplicationClass();  
  2.   
  3. //ヘッダーテキストをエクセルに送る  
  4. for(int i = 1; i < dataGridView1->Columns->Count + 1 ; i++){  
  5.    ap1->Cells[1,i] = dataGridView1->Columns[i-1]->HeaderText;  
  6. }  
  7.   
  8. //行と列をエクセルに送る  
  9. forint i = 0 ; i < (dataGridView1->Rows->Count-1) ; i++ ){  
  10.    forint j = 0 ; j < (dataGridView1->Columns->Count) ; j++ ){      
  11.    ap1->Cells[i + 2 , j + 1] = dataGridView1->Rows[i]->Cells[j]->Value->ToString();  
  12.    }  
  13. }  
  14.   
  15. ap1->Visible = true;  

0 件のコメント:

コメントを投稿