导出excel方法一
#region 导出Excel
private void ExportToXls(DataTable dt)
{
if (dt != null)
{
IReport p = new Report();
ExcelPage ep = new ExcelPage();
ep.name = “export.xls”;
ExcelRow er = new ExcelRow();
foreach (DataColumn c in dt.Columns)
{
ExcelColumn ec = new ExcelColumn();
ec.value = c.ColumnName;
er.Columns.Add(ec);
}
ep.Rows.Add(er);
foreach (DataRow row in dt.Rows)
{
ExcelRow er1 = new ExcelRow();
foreach (DataColumn c in dt.Columns)
{
ExcelColumn ec = new ExcelColumn();
ec.value = row[c.ColumnName].ToString();
er1.Columns.Add(ec);
}
ep.Rows.Add(er1);
}
p.DataSource.Add(ep);
p.InitData(Context);
}
}
#endregion