将旧的数据表存放到新的数据表中

#region 将旧的数据表存放到新的数据表中      public static DataTable TableAppendToOtherTable(DataTable dt, string strSession)
        /// <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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值