在Visual   Studio   .NET中建立一个C#   WinForm工程.     
  添加Microsoft   Excel   Object   Library引用:     
  右键单击Project   ,   选“添加引用”     
  在COM   标签项,选中   locate   Microsoft   Excel   Object   Library     
  点确定按钮完成添加引用。   On   the   View   menu,   select   Toolbox   to   display   the   Toolbox.   Add   two   buttons   and   a   check   box   to   Form1.     
  在Form1上添加一个button1,双击   Button1,添加click事件的代码.把数组里的数据填到Excel表格。     
  首先添加引用:     
    
  using   System.Reflection;     
  using   Excel   =   Microsoft.Office.Interop.Excel;     
    
    
  声明两个类的成员变量     
  Excel.Application   objApp;     
  Excel._Workbook   objBook;     
    
  private   void   button1_Click(object   sender,   System.EventArgs   e)     
  {     
  Excel.Workbooks   objBooks;     
  Excel.Sheets   objSheets;     
  Excel._Worksheet   objSheet;     
  Excel.Range   range;     
    
  try     
  {     
  //   Instantiate   Excel   and   start   a   new   workbook.     
  objApp   =   new   Excel.Application();     
  objBooks   =   objApp.Workbooks;     
  objBook   =   objBooks.Add(   Missing.Value   );     
  objSheets   =   objBook.Worksheets;     
  objSheet   =   (Excel._Worksheet)objSheets.get_Item(1);     
    
  //Get   the   range   where   the   starting   cell   has   the   address     
  //m_sStartingCell   and   its   dimensions   are   m_iNumRows   x   m_iNumCols.     
  range   =   objSheet.get_Range("A1",   Missing.Value);     
  range   =   range.get_Resize(5,   5);     
    
  if   (this.FillWithStrings.Checked   ==   false)     
  {     
  //Create   an   array.     
  double[,]   saRet   =   new   double[5,   5];     
    
  //Fill   the   array.     
  for   (long   iRow   =   0;   iRow   <   5;   iRow++)     
  {     
  for   (long   iCol   =   0;   iCol   <   5;   iCol++)     
  {     
  //Put   a   counter   in   the   cell.     
  saRet[iRow,   iCol]   =   iRow   *   iCol;     
  }     
  }     
    
  //Set   the   range   value   to   the   array.     
  range.set_Value(Missing.Value,   saRet   );     
  }     
    
  else     
  {     
  //Create   an   array.     
  string[,]   saRet   =   new   string[5,   5];     
    
  //Fill   the   array.     
  for   (long   iRow   =   0;   iRow   <   5;   iRow++)     
  {     
  for   (long   iCol   =   0;   iCol   <   5;   iCol++)     
  {     
  //Put   the   row   and   column   address   in   the   cell.     
  saRet[iRow,   iCol]   =   iRow.ToString()   +   "|"   +   iCol.ToString();     
  }     
  }     
    
  //Set   the   range   value   to   the   array.     
  range.set_Value(Missing.Value,   saRet   );     
  }     
    
  //Return   control   of   Excel   to   the   user.     
  objApp.Visible   =   true;     
  objApp.UserControl   =   true;     
  }     
  catch(   Exception   theException   )     
  {     
  String   errorMessage;     
  errorMessage   =   "Error:   ";     
  errorMessage   =   String.Concat(   errorMessage,   theException.Message   );     
  errorMessage   =   String.Concat(   errorMessage,   "   Line:   "   );     
  errorMessage   =   String.Concat(   errorMessage,   theException.Source   );     
    
  MessageBox.Show(   errorMessage,   "Error"   );     
  }     
  }