• 欢迎访问小杰博客网站
  • 欢迎访问小杰博客网站哦

php导出excel数据

未分类 小杰 4年前 (2015-04-13) 165次浏览 已收录 0个评论

// xls,xlsx格式的
$title = array(0=>array(‘仓库’,’快递’,’省’,’市’,’区’,’首重’,’首重费’,’续重费’,’面单费’,’操作费’,’过磅费’,’中转费’,’最低中转费’,’价格权重’,’质量权重’,’时效权重’,’售后权重’,’可达性权重’));
// $data = array(0=>array(‘6936986833094′,’4′,’良品’),
//              1=>array(‘6936986832097′,’5′,’良品’));
$data = array();              
foreach($region_list as $region) {
$row = array();
$row[] = $region[‘facility_name’];
$row[] = $region[‘shipping_name’];
$row[] = $region[‘province_name’];
$row[] = $region[‘city_name’];
$row[] = $region[‘district_name’];
$row[] = $region[‘first_weight’];
$row[] = $region[‘first_fee’];
$row[] = $region[‘continued_fee’];
$row[] = $region[‘tracking_fee’];
$row[] = $region[‘operation_fee’];
$row[] = $region[‘weighing_fee’];
$row[] = $region[‘transit_fee’];
$row[] = $region[‘lowest_transit_fee’];
$row[] = $region[‘price_weight’];
$row[] = $region[‘quality_weight’];
$row[] = $region[‘time_arrived_weight’];
$row[] = $region[‘service_weight’];
$row[] = $region[‘arrived_weight’];

$data[] = $row;
}

$file_name = ‘地区费用列表.xlsx’;
$type = array();
for($i=0;$i<count($data[0]);$i++) {
$type[] = ‘string’;
}
excel_export_model($title,$file_name,$data,$type,’地区费用列表’);

exit ();

function excel_export_model($title, $filename, $data, $type, $sheetname=””)
{
    set_include_path(get_include_path() . PATH_SEPARATOR .ROOT_PATH. ‘admin/includes/Classes/’);
    require_once ‘PHPExcel.php’;
    require_once ‘PHPExcel/IOFactory.php’;
    
    $excel = new PHPExcel();
    $sheet = $excel->getActiveSheet();
    $sheet->fromArray($title);
    if (!empty($data)) {
        $sheet->fromArray($data, null, ‘1’, $type);
    }
    if(!empty($sheetname)) {
    $sheet->setTitle($sheetname);
    } else {
    $sheet->setTitle(‘批量导入’);
    }
    
    $output = PHPExcel_IOFactory::createWriter($excel, ‘Excel2007’);
    $output->setOffice2003Compatibility(true);
    
    header(‘Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’);
    header(‘Content-Disposition: attachment; filename=”‘ . $filename . ‘”‘);
    header(‘Cache-Control: max-age=0’);
    $output->save(‘php://output’);
    
    exit();
}


小杰博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php导出excel数据
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址