First, download the latest class files from the official phpExcel website. The following is a small example of Chinese garbled characters.
/** PHPExcel */require_once '.. /Classes/PHPExcel. php '; // Create new PHPExcel object $ objPHPExcel = new PHPExcel (); // connect to the database to obtain data $ conn = mysql_connect ('localhost', 'root ',''); if (! $ Conn) die ('database connection failed'); mysql_select_db ('test'); mysql_set_charset ('utf8'); $ SQL = "SELECT * FROM orders "; $ query = mysql_query ($ SQL); $ objPHPExcel-> setActiveSheetIndex (0)-> setCellValue ('a1', mb_convert_encoding ('sequence number ', 'utf-8 ', 'gbk')-> setCellValue ('b1 ', mb_convert_encoding ('real name', 'utf-8', 'gbk')-> setCellValue ('c1 ', mb_convert_encoding ('money', 'utf-8', 'gbk'); $ num = 2; while ($ row = mysql_fetch_array ($ query )) {$ objPHPExcel-> setActiveSheetIndex (0)-> setCellValue ('A '. $ num, $ row ['id'])-> setCellValue ('B '. $ num, $ row ['realname'])-> setCellValue ('C '. $ num, $ row ['momeny']); $ num ++;} // Rename sheet $ objPHPExcel-> getActiveSheet ()-> setTitle ('simple '); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $ objPHPExcel-> setActiveSheetIndex (0 ); // Redirect output to a client's web browser (Excel5) header ('content-Type: application/vnd. ms-excel '); header ('content-Disposition: attachment; filename = "01simple.xls"'); header ('cache-Control: max-age = 0 '); $ objWriter = PHPExcel_IOFactory: createWriter ($ objPHPExcel, 'excel5'); $ objWriter-> save ('php: // output'); exit;