1<?PHP2 /*3 * Functions of the class4 * Incoming two-bit array export Excel5 * Incoming Excel export two-bit array6 * @author Mrwu7 */8 require(' phpexcel.php ');9 require_once' Phpexcel/reader/excel5.php '; Ten include' Phpexcel/iofactory.php '; One A classPlugin_phpexcel - { - Private $export _excel_title;//Export Excel title the Private $export _sheet_title;//Export Sheet Title - Private $letters; - Private $php _excel;//Php_excel Operation class - Private $active _sheet; + - function__construct ($export _excel_title= ' Excel ',$export _sheet_title= ' Sheet1 ') + { A $this->letters=Range(' A ', ' Z ', 1); at $this->php_excel=NewPhpexcel (); - $this->php_excel->setactivesheetindex (0); - $this->active_sheet=$this->php_excel->Getactivesheet (); - $this->export_excel_title=$export _excel_title; - $this->export_sheet_title=$export _sheet_title; - } in - /* to * $title = ' title ' Array + * $import _arr Insert an array of Excel requires a two-bit array - */ the functionExport$title=Array(),$import _arr) * { $ //have the title set for the first line of ExcelPanax Notoginseng if($title) - { the $count=Count($title); + for($i= 0;$i<=$count;$i++) A { the $this->active_sheet->setcellvalue ($this->letters[$i].‘ 1 ',$title[$i]); + } - } $ //Loop into a two-dimensional array $ $count=Count($import _arr[0]); - $row=1; - foreach($import _arr as $value) the { - Wuyi $row++; the $j=0; - foreach($value as $key=$v) Wu { - $this->active_sheet->setcellvalue ($this->letters[$j].$row,$v); About Echo $value[$j]; $ $j++; - } - } - $phpWriter=phpexcel_iofactory::createwriter ($this->php_excel, ' Excel5 '); A //set some headings, etc. + $file=$this-Export_excel_title; the $this->active_sheet->settitle ($this-export_sheet_title); - $ //Set Header the Header("Pragma:public"); the Header("expires:0"); the Header("Cache-control:must-revalidate, post-check=0, pre-check=0"); the Header("Content-type:application/force-download"); - Header("Content-type:application/vnd.ms-execl"); in Header("Content-type:application/octet-stream"); the Header("Content-type:application/download"); the Header(' content-disposition:attachment;filename= ' Excel.xls "'); About Header("Content-transfer-encoding:binary"); the the $phpWriter->save (' Php://output '); the + - } the }Bayi //Test the $php _excel=NewPlugin_phpexcel (' Excel ', ' Sheet1 '); the $php _excel->export (Array(' title ', ' content '),Array(Array(' title ' = ' haha ', ' content ' = ' shit '),Array(' title ' = ' hehe ', ' content ' = ' fuck '));
Excel class based on Phpexcel write (export as Excel)