码迷,mamicode.com
首页 > 其他好文 > 详细

CI框架——excel表导出功能

时间:2017-05-26 19:37:51      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:日期   val   excel   else   star   记录   sop   ==   foreach   

public function export_list(){

//导入Excel类
$this->load->library(‘excel‘);

//制作Excel标题
$this->excel->filename = ‘订单表‘;

//制作Excel表头参数
$titles = array(‘姓名‘,‘日期‘,‘来源‘);
$pagesize = 10000;      //定义表量
$where = ‘1=1‘;

$start_time = empty($_REQUEST[‘start_time‘]) ? ‘‘ : (strpos($_REQUEST[‘start_time‘], ‘-‘) > 0 ? strtotime($_REQUEST[‘start_time‘]) : $_REQUEST[‘start_time‘]);
$end_time = empty($_REQUEST[‘end_time‘]) ? ‘‘ : (strpos($_REQUEST[‘end_time‘], ‘-‘) > 0 ? strtotime($_REQUEST[‘end_time‘]) : $_REQUEST[‘end_time‘]);

if ($this->input->get(‘shipping‘) != ‘‘) {
$where .= " AND shipping_id =" . $this->input->get(‘shipping‘) . "";
}

$where .= " AND shipping_sn<>‘‘ ";
if (!empty($start_time)) {
$where .= " AND shipping_time >= ‘" . $start_time . "‘";
}
if (!empty($end_time)) {
$where .= " AND shipping_time <= ‘" . $end_time . "‘";
}

/* 自定义每页条数 */
if (!empty($_GET[‘select_pages‘])) {
$pagesize = $this->input->get(‘select_pages‘);
}

$count_page = $this->db->count_all_results(‘gbsop_order_info‘); //计算数据总记录数

$curr = 1;
if ($curr == 1) {
$curr = ‘‘;
} elseif ($curr == 2) {
$curr = $pagesize;
} elseif ($curr != 1 && $curr != 2) {
$curr = $pagesize * $curr - $pagesize;
}

$this->load->model(‘m_order‘); //导入模型

//获取表内容
$array = array();
$mysql = $this->m_order->get_order_list($pagesize, $curr, $where);

//获取表参数
foreach ($mysql as $key => $val) {
$array[$key][‘name‘] = $val[‘consignee‘];
$array[$key][‘date‘] = empty($val[‘shipping_time‘]) ? ‘‘ : date(‘Y-m-d h:i:s‘, $val[‘shipping_time‘]);
$array[$key][‘referer‘]=$val[‘referer‘];
}

//生成Excel表
$this->excel->make_from_array($titles, $array);
}

CI框架——excel表导出功能

标签:日期   val   excel   else   star   记录   sop   ==   foreach   

原文地址:http://www.cnblogs.com/zgxblog/p/6910027.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!