/// <summary>
/// 将旧的数据表存放到新的数据表中
/// </summary>
/// <param name="dt">原有数据表</param>
/// <param name="strSession">新数据表名</param>
/// <returns>返回新的数据表</returns>
public static DataTable TableAppendToOtherTable(DataTable dt, string strSession)
{
DataTable table = new DataTable();
if (HttpContext.Current.Session[strSession] == null)
{
HttpContext.Current.Session[strSession] = dt;
return dt;
}
else
{
//原来的数据表
DataTable d = HttpContext.Current.Session[strSession] as DataTable;
table = d.Copy();
table.ImportRow(dt.Rows[0]);
return table;
}
}
#endregion
//批量导出Excel
#region 导出勾选结果
protected void btnCross_Click(object sender, EventArgs e)
{
DataTable d = null;
foreach (RepeaterItem item in rptList.Items)
{
CheckBox cb = item.FindControl("cbItems") as CheckBox;
if (cb.Checked)
{
Literal ltr = item.FindControl("ltrId") as Literal;
int id = Convert.ToInt32(ltr.Text.Trim());
sql = "select wt_id as 编号,wt_title as '操作名称',wt_caozuo as '操作',wt_price as '金额',wt_userId as '用户名',wt_sjbs as '收件标示', wt_sjdh as '收件代号',wt_remark as '内容',wt_addtime as '时间' from wd_finance where wt_id=" + id;
DataTable dt = HtmlHelper.GetData(sql);
d = ExcelHelper.TableAppendToOtherTable(dt, "finance");
}
}
string strPath = Server.MapPath(@"~/UpFile/excel/get/models.xls");
ExcelHelper.TableToExcelForXLS(d, strPath);
HtmlHelper.FileDown("models.xls", strPath);
}
#endregion