/// <summary>
/// 将DataTable数据写入Excel文件(不分页)
/// </summary>
/// <param name="dt">DataTable</param>
/// <param name="top">表格数据起始行索引</param>
/// <param name="left">表格数据起始列索引</param>
public void DataTableToExcel(DataTable dt,int top,int left)
{
int rowCount = dt.Rows.Count; //DataTable行数
int colCount = dt.Columns.Count; //DataTable列数
//利用二维数组批量写入
string[,] arr = new string[rowCount,colCount];
for(int j=0;j<rowCount;j++)
{
for(int k=0;k<colCount;k++)
{
arr[j,k] = dt.Rows[j][k].ToString();
}
}
range = (Excel.Range)workSheet.Cells[top,left];
range = range.get_Resize(rowCount,colCount);
range.Value = arr;
}