Here the export CSV format file and export Excel is similar, you can refer to the code, to achieve the export function.
/** * CSV export */public function exportvoter () {Header ("cache-control:public"); Header ("Pragma:public"); Header ("content- Type:application/vnd.ms-excel "); header (" Content-disposition:attachment;filename= voter information. csv "); Header (' Content-type:application/octet-stream '); Ob_start (); $header _str = iconv ("Utf-8", ' GBK ', "name, gender, telephone, password \ n"); $ Voter = new \admin\model\votersmodel ();//$data = I (' Get. '); Print_r ($data); exit (); if (I (' get.name ') = "") {$name = I (' Get.name ');} else {$name = "";} $where = ($name = = '? ': "and v.name like '%{$name}% '); $list = $voter->query (" Select v.*,d.deptname from voters v inner Join Wkrj_auth_dept D on V.deptid=d.id ". $where); $file _str=", if ($list) {foreach ($list as $row) {$file _str.= $row [' name ' ]. ', '. $row [' sex ']. ', '. $row [' phone ']. ', ' $row [' Password ']. " \ n ";}} Else{echo "Export failed!";} Exit ($file _str);//iconv transcoding function $file_str= iconv ("Utf-8", ' GBK ', $file _str); Ob_end_clean (); Echo $header _str;echo $file _str;}
The above describes the thinkphp export CSV format documents, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.