Use PHP export excel documents, sometimes inexplicably garbled data will be exported, now recommend a universal repair Dafa
Man of few words said, directly on the code
After the core is finished processing the data, adding ob_end_clean () function before outputting excel file; see specific example code, only part of the code listed here
1 foreach ($licenseList as $key => $item) { 2 $objPHPExcel->setActiveSheetIndex(0) 3 ->setCellValue('A' . ($key + 2), $item["company_name"]) 4 ->setCellValue('B' . ($key + 2), $item["user_name"]) 5 ->setCellValue('C' . ($key + 2), $item["order_number"]) 6 ->setCellValue('D' . ($key + 2), $item['apply_type']==2 ? 'official':'trial') 7 ->setCellValue('E' . ($key + 2), $item["license_key"]) 8 ->setCellValue('F' . ($key + 2), $statusArr[$item['license_status']])->setCellValue('G' . ($key + 2), $item["user_email"]) 9 ->setCellValue('H' . ($key + 2), date('y/m/d H:i:s', strtotime($item['insert_time']))); 10 } . 11 12 is $ objPHPExcel -> getActiveSheet () -> setTitle ( 'the Simple' ); 13 is $ objPHPExcel -> setActiveSheetIndex (0 ); 14 ob_end_clean (); // solution in the core here to add distortion this function 15 header ( 'the Type-the Content: file application / vnd.ms-Excel' ); 16 header ( 'the Content-Disposition: Attachment; filename = "test_list.xls"' ); . 17 header ( 'the Cache-Control: max- = 0 Age ' ); 18 is header (' the Cache-Control: max-Age =. 1 ' ); . 19 header (' the Expires: Mon, 26 is Jul-1997 05:00:00 GMT '); 20 header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); 21 header('Cache-Control: cache, must-revalidate'); 22 header('Pragma: public'); 23 24 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); 25 $objWriter->save('php://output'); 26 exit;
As red mark shown in the code, if this method does not work, try using iconv () function, not the specific use Detailed here, please self Baidu
Good luck!