打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
php excel导出
/** * 导出节目单 */public function programExport_ExcelAction($data,$catid){    require_once dirname(__FILE__) . '/PHPExcel.class.php';    $sheetname = 'sheet1';    $catname = $this->category_cache[$catid]['catname'];    $savefile = $catname . "节目单";    //设置表格头部    $title = array('ID', '标题', '推荐','资源状态','栏目','版权上线时间','版权下线时间','版权到期时间','审核状态','发布人','更新时间'); //设置要导出excel的表头    $objPHPExcel = new PHPExcel();    //设置列头标题    for ($i = 0; $i < count($title); $i  ) {        $alpha = chr(65   $i);        $objPHPExcel->getActiveSheet()->setCellValue($alpha.'1', $title[$i]);        $objPHPExcel->getActiveSheet()->getColumnDimension($alpha)->setWidth(20);//设置列宽        $objPHPExcel->getActiveSheet()->getStyle($alpha)->getAlignment()->setWrapText(true); //单元宽度自适应        $objPHPExcel->getActiveSheet()->getStyle($alpha . '1')->getFont()->setName("Candara");  //设置字体        $objPHPExcel->getActiveSheet()->getStyle($alpha . '1')->getFont()->setSize(12);  //设置大小        $objPHPExcel->getActiveSheet()->getStyle($alpha . '1')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_BLACK); //设置颜色        $objPHPExcel->getActiveSheet()->getStyle($alpha . '1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //水平居中        $objPHPExcel->getActiveSheet()->getStyle($alpha . '1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); //垂直居中        $objPHPExcel->getActiveSheet()->getStyle($alpha . '1')->getFont()->setBold(true); //加粗        $objPHPExcel->getActiveSheet()->getStyle($alpha.'1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);//设置颜色        $objPHPExcel->getActiveSheet()->getStyle($alpha.'1')->getFill()->getStartColor()->setARGB('FF97BAE5');        $objPHPExcel->getActiveSheet()->getStyle($alpha)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //水平居中        $objPHPExcel->getActiveSheet()->getStyle($alpha)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); //垂直居中    }    for($j = 0;$j<count($data);$j  ){        $z = $j   2;        $objPHPExcel->getActiveSheet()->setCellValue('A'.$z, $data[$j]['id']);        $objPHPExcel->getActiveSheet()->setCellValue('B'.$z, $data[$j]['title']);        //推荐        $content_model = get_cache('content_model');        $content_model = $content_model[$this->category_cache[$catid]['modelid']][fields];        $tuijianarr = $content_model['shouyetuijian'][setting];//地区的设置        $tuijianarr = string2array($tuijianarr);//把文本专为数组        $tuijianarr = explode(chr(13), $tuijianarr[content]);//分割数组 分割条件是一行一个        //分解数组        $tuijian = string2array($data[$j]['shouyetuijian']);        $shouyetuijian = '';        foreach ($tuijianarr as $qt) {            list($select_name, $select_value) = explode('|', $qt);            if (in_array($select_value, $tuijian) && $select_value != -1) {                $shouyetuijian .= ' '.$select_name;            }        }        $objPHPExcel->getActiveSheet()->setCellValue('C'.$z,$shouyetuijian );        //资源状态        if($data[$j]['isonline'] == '0'){            $isonline = '已上架';        }else if($data[$j]['isonline'] == '1'){            $isonline = '已下架';        }else if($data[$j]['isonline'] == '3'){            $isonline = '';        }        $objPHPExcel->getActiveSheet()->setCellValue('D'.$z, $isonline);        $objPHPExcel->getActiveSheet()->setCellValue('E'.$z, $catname);        //版权上线时间        if($data[$j]['uponlinetime']){            $uponlinetime = date('Y-m-d', $data[$j]['uponlinetime']);        }else{            $uponlinetime = '无';        }        $objPHPExcel->getActiveSheet()->setCellValue('F'.$z, $uponlinetime);        //版权下线时间        if($data[$j]['downonlinetime']){            $downonlinetime = date('Y-m-d', $data[$j]['downonlinetime']);        }else{            $downonlinetime = '无';        }        $objPHPExcel->getActiveSheet()->setCellValue('G'.$z, $downonlinetime);        //版权到期时间        if($data[$j]['timeoff']){            $timeoff = $data[$j]['timeoff'];        }else{            $timeoff = '无';        }        $objPHPExcel->getActiveSheet()->setCellValue('H'.$z, $timeoff);        //审核状态        if(!$data[$j]['aduitstate']){            $aduitstate = '未审核';        }else if($data[$j]['aduitstate'] == '1'){            $aduitstate = '审核成功';        }else if($data[$j]['aduitstate'] == '2'){            $aduitstate = '待修改';        }        $objPHPExcel->getActiveSheet()->setCellValue('I'.$z, $aduitstate);        $objPHPExcel->getActiveSheet()->setCellValue('J'.$z, $data[$j]['username']);        $objPHPExcel->getActiveSheet()->setCellValue('K'.$z, date('Y-m-d', $data[$j]['time']));    }    $objPHPExcel->getActiveSheet()->setTitle($sheetname); //题目    $objPHPExcel->setActiveSheetIndex(0); //设置当前的sheet    header('Content-Type: application/vnd.ms-excel');    header('Content-Disposition: attachment;filename="' . $savefile . '.xls"');//文件名称    header('Cache-Control: max-age=0');    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); //Excel5    $objWriter->save('php://output');}
来源:http://www.icode9.com/content-1-148901.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
PHP简单导出Excel表格
php 生成 excel 的标准类库 非常好用兼容性超强
【前端】有如此利器,Excel导出体验就是好
PHP导出Excel的类库—PHPExcel,支持附带图片
php 导出excel (html)
第6期:PHP新手入门专题 - PHP论坛|PHP教程|PHP源码|PHP下载|PHP培训...
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服