首页 > 代码库 > CI框架——excel表导出功能

CI框架——excel表导出功能

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表导出功能