以下是代码:                   
                  /// <summary>
/// 增加表头
/// </summary>
private void addExcelHeader()
{
excel = new   Microsoft.Office.Interop.Excel.Application ();
rowIndex=1;
colIndex=0;
excel.Application.Workbooks.Add(true); table=ds.Tables[0]; //将所得到的表的列名,赋值给单元格
foreach(DataColumn col in table.Columns)
{
colIndex++; 
excel.Cells[1,colIndex]=col.ColumnName;
}
}
/// <summary>
/// 增加数据
/// </summary>
public void addExcelBody()
{
//同样方法处理数据
foreach(DataRow row in table.Rows)
{
rowIndex++;
colIndex=0;
foreach(DataColumn col in table.Columns)
{
colIndex++;
excel.Cells[rowIndex,colIndex]=row  [col.ColumnName].ToString();
}
}
//不可见,即后台处理
excel.Visible=true;
this.btn_report.Enabled = true;

}