Home > php教程 > php手册 > phpexcel导出

phpexcel导出

WBOY
Release: 2016-06-07 11:39:32
Original
1212 people have browsed it

这里只粘贴了使用的代码,里面需要引用phpexcel,在上面搜索phpexcel就有很多下载的
/**<br>      * 客户导出<br>      *<br>      **/<br>     public function excelExport($customerList=false){<br>         C('OUTPUT_ENCODE', false);<br>         import("ORG.PHPExcel.PHPExcel");<br>         $objPHPExcel = new PHPExcel();    <br>         $objProps = $objPHPExcel->getProperties();<br>         $objPHPExcel->setActiveSheetIndex(0);     <br>         $objActSheet = $objPHPExcel->getActiveSheet(); <br>            <br>         $objActSheet->setTitle('Sheet1');<br>         $ascii = 65;<br>         $cv = '';<br>         //联系人字段<br>         $contacts_fields_list = array();<br>         $contacts_fields_list[0]['field'] = 'name';<br>         $contacts_fields_list[0]['name'] = '用户名';<br>         $contacts_fields_list[1]['field'] = 'telephone';<br>         $contacts_fields_list[1]['name'] = '电话';<br>         <br>         foreach($contacts_fields_list as $field){<br>             $objActSheet->setCellValue($cv.chr($ascii).'1', $field['name']);<br>             $ascii++;<br>             if($ascii == 91){<br>                 $ascii = 65;<br>                 $cv .= chr(strlen($cv)+65);<br>             }<br>         }<br>         <br>         /*$where['owner_role_id'] = array('in',implode(',', getSubRoleId()));<br>         $where['is_deleted'] = 0;*/<br>         $list = M('user')->select();<br>         $ascii = 65;<br>         $cv = '';<br>         $i = 2;<br>         foreach($list as $val){<br>             foreach($contacts_fields_list as $valu){<br>                 //防止使用科学计数法,在数据前加空格<br>                 if($valu['field'] == 'telephone' || $valu['field'] =='qq'){<br>                     $objActSheet->setCellValue($cv.chr($ascii).$i, ' '.$val[$valu['field']]);<br>                 }else{<br>                     $objActSheet->setCellValue($cv.chr($ascii).$i, $val[$valu['field']]);<br>                 }<br>                 <br>                 $ascii++;<br>                 if($ascii == 91){<br>                     $ascii = 65;<br>                     $cv .= chr(strlen($cv)+65);<br>                 }<br>             }<br>             $ascii = 65;<br>             $cv = '';<br>             $i++;<br>         } <br> <br>         $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');<br>         ob_end_clean();<br>         header("Content-Type: application/vnd.ms-excel;");<br>         header("Content-Disposition:attachment;filename=5kcrm_user_".date('Y-m-d',mktime()).".xls");<br>         header("Pragma:no-cache");<br>         header("Expires:0");<br>         $objWriter->save('php://output'); <br>     }这里只粘贴了使用的代码,里面需要引用phpexcel,在上面搜索phpexcel就有很多下载的

再来一个简单的导出的方法:public function oexcel()<br>     {<br>         header('Content-Type: application/vnd.ms-excel');<br>         header('Content-Disposition: attachment; filename=user.xls');<br>         header('Pragma: no-cache');<br>         header('Expires: 0');<br>         $title = array('手机', '昵称');<br>         $data = M('user')->field("login,uname")->select();<br>         echo iconv('utf-8', 'gbk', implode("\t", $title)), "\n";<br>         foreach ($data as $value) {<br>             echo iconv('utf-8', 'gbk', ' '.implode("\t", $value)), "\n";<br>         }<br> <br>     }

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template