• 使用phpexcel导出 数据


     require_once('PHPExcel.php');	
         $title='商户明细'; $header=array( 'id'=>'商户ID', 'post_date_gmt'=>'认证开始日期', 'post_title'=>'门店名称', 'post_status'=>'状态', 'tel'=>'联系电话', 'name'=>'姓名', 'display_name'=>'运营中心', 'centname'=>'代理商', 'shi'=>'市县', 'sheng'=>'省份', 'autimeend'=>'认证结束日期' ); function exportExcel($title,$header,$data){ $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("Maarten Balliauw") ->setLastModifiedBy("Maarten Balliauw") ->setTitle($title) ->setSubject($title) ->setDescription("描述") ->setKeywords("office PHPExcel php") ->setCategory("Test result file"); //得到当前活动的表 $objActSheet = $objPHPExcel->getActiveSheet(); $objActSheet->setTitle($title); // 文件名 $filename=date('Ymdhis',time()).".xls"; $fileName = iconv("utf-8", "gb2312", $fileName); //设定各列宽度 //设置表头 $key = ord("A"); foreach($header as $v){ $colum = chr($key); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue($colum.'1', $v); $key += 1; } $column = 2; $objActSheet = $objPHPExcel->getActiveSheet(); foreach($data as $key => $rows){ //行写入 $span = ord("A"); foreach($rows as $keyName=>$value){// 列写入 $j = chr($span); $objActSheet->setCellValue($j.$column, $value); $span++; } $column++; } header('Content-Type: application/vnd.ms-excel'); header("Content-Disposition: attachment;filename=".$filename); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); }

    //调用函数输出
    exportExcel($title,$header,$rs);

      

  • 相关阅读:
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
    volcanol的工控博客
  • 原文地址:https://www.cnblogs.com/xuedong/p/5652426.html
Copyright © 2020-2023  润新知