Ejemplo n.º 1
0
 //导出数据到Excel
 protected void lBtnToExcel_Click(object sender, EventArgs e)
 {
     //获取数据并填充到数据表
     using (var da = new t_delivery_bill_lot_cardTableAdapter())
     {
         //检测session中保存的查询条件
         object obj = Session["delivery_lot_card_mgr_where_content"];
         string str = string.Empty;
         if (obj != null && obj.ToString().Length > 0)
         {
             str = obj.ToString();
         }
         //获取前1万行数据
         var tab = da.GetPagedData(0, 10000, str, "order by [id] desc");
         //设置列标题
         string[] titleCol = "序号,送货单序号,行号,批量卡序号,pcs数量,备注".Split(',');
         //设置表名称
         string titleTab = "送货单批量卡清单";
         //临时文件名称
         string fileName = titleTab + DateTime.Now.ToString("yyMMddHHmmss") + ".xls";
         //执行导出数据到excel
         bool isSuccess = ydPublicMethod.DataTable2Excel(tab, titleCol, ref fileName, titleTab);
         //如果成功则跳转到指定页面
         if (isSuccess)
         {
             Response.Redirect(fileName);
             //停止加载后续内容
             Response.End();
         }
     }
 }