If garbled when exporting Chinese, you can try to convert the string to gb2312, for example$yourStr from UTF-8 converted into a gb2312:$yourStr= Mb_convert_encoding ("gb2312", "UTF-8",$yourStr); Summary PHP Export Excel PHP import Excel phpexcel Instructions phpexcel user manual1: First recommendation of Phpexcel, official website: http://Www.codeplex.com/PHPExcelImport and export, you can export office2007 format, and compatible with 2003. The downloaded package has documentation and examples that you can study on your own. <?//to set the include path for the Phpexcel class librarySet_include_path(‘.‘. Path_separator. ' D:\workspace\biznaligy_eh\dev_src\includes\PHPExcel '. Path_separator.Get_include_path()); /** * The following is an example of use, for a line beginning with////is a different alternative, please open the corresponding line comment according to the actual need. * If you use Excel5, the content of the output should be GBK encoded. */ require_once' Phpexcel.php '; require_once' phpexcel/writer/excel5.php ';//for other low version xls require_once' phpexcel/writer/excel2007.php ';//for excel-2007 format//Create a Processing object instance $objExcel=NewPhpexcel ();//create a file format to write to an object instance, uncomment $objWriter=NewPhpexcel_writer_excel5 ($objExcel);//for other version formats//or//$objWriter = new phpexcel_writer_excel2007 ($objExcel);//For 2007 formats//$objWriter->setoffice200 3Compatibility (TRUE); Set document basic Properties $objProps=$objExcel-getProperties (); $objProps->setcreator ("Zeal Li"); $objProps->setlastmodifiedby ("Zeal Li"); $objProps->settitle ("Office XLS Test Document"); $objProps->setsubject ("Office XLS Test Document, Demo"); $objProps->setdescription ("Test document, generated by Phpexcel.")); $objProps->setkeywords ("Office Excel Phpexcel"); $objProps->setcategory ("Test"); //sets the current sheet index for subsequent content operations. It is generally only necessary to display a call when multiple sheet are used. By default, Phpexcel automatically creates the first sheet to be set sheetindex=0 $objExcel->setactivesheetindex (0); $objActSheet=$objExcel-Getactivesheet ();//sets the name of the currently active sheet $objActSheet->settitle (' Test sheet '); //Set cell contents automatically determine cell content type by phpexcel based on incoming content $objActSheet->setcellvalue (' A1 ', ' string content ');//string Content $objActSheet->setcellvalue (' A2 ', 26);//value $objActSheet->setcellvalue (' A3 ',true);//Boolean value $objActSheet->setcellvalue (' A4 ', ' =sum (A2:A2) ');//Formula//explicitly specify content type $objActSheet->setcellvalueexplicit (' A5 ', ' 8757584 ', Phpexcel_cell_datatype::type_string); //Merge Cells $objActSheet->mergecells (' B1:c22 '); //Separating cells $objActSheet->unmergecells (' B1:c22 '); //Set Width $objActSheet->getcolumndimension (' B ')->setautosize (true); $objActSheet->getcolumndimension (' A ')->setwidth (30); //sets the number format for the contents of the cell. If you use Phpexcel_writer_excel5 to generate content,//You need to note that in the Phpexcel_style_numberformat class, the const variable definition//Various custom formatting methods, Other types can be used normally, but when setformatcode//is format_number, the actual effect is not formatted as "0". Need//Modify the GETXF ($style) method in the Phpexcel_writer_excel5_format class source code,//in front of if ($this->_biff_version = = 0x0500) {(Near line No. 363) Add a//Line code://if ($ifmt = = = ' 0 ') $ifmt = 1; Format to Phpexcel_style_numberformat::format_number, avoid some large numbers//are used scientific notation display, with the following Setautosize method can let each line of content// Are all displayed according to the original content. $objStyleA 5=$objActSheet->getstyle (' A5 '); $objStyleA 5->getnumberformat ()->setformatcode (Phpexcel_style_numberformat::format_number); //Set Font $objFontA 5=$objStyleA 5-GetFont (); $objFontA 5->setname (' Courier New '); $objFontA 5->setsize (10); $objFontA 5->setbold (true); $objFontA 5->setunderline (Phpexcel_style_font::underline_single); $objFontA 5->getcolor ()->setargb (' FFFF0000 ')) ; $objFontA 5->getcolor ()->setargb (Phpexcel_style_color::color_white);//$ objFontA5->getfont ()->setcolor (phpexcel_style_color::color_red);//Set Alignment $objAlignA 5=$objStyleA 5-getalignment (); $objAlignA 5->sethorizontal (phpexcel_style_alignment::horizontal_right); $objAlignA 5->setvertical (phpexcel_style_alignment::vertical_center); //Set Border $objBorderA 5=$objStyleA 5-getborders (); $objBorderA 5->gettop ()->setborderstyle (Phpexcel_style_border::Border_thin); $objBorderA 5->gettop ()->getcolor ()->setargb (' FFFF0000 ');//Border Color $objBorderA 5->getbottom ()->setborderstyle (Phpexcel_style_border::Border_thin); $objBorderA 5->getleft ()->setborderstyle (Phpexcel_style_border::Border_thin); $objBorderA 5->getright ()->setborderstyle (Phpexcel_style_border::Border_thin); //Set cell fill Color $objFillA 5=$objStyleA 5-Getfill (); $objFillA 5->setfilltype (Phpexcel_style_fill::fill_solid); $objFillA 5->getstartcolor ()->setargb (' ffeeeeee ')); //copies the style information from the specified cell. $objActSheet->duplicatestyle ($objStyleA 5, ' B1:c22 '); //Add a picture $objDrawing=Newphpexcel_worksheet_drawing (); $objDrawing->setname (' zealimg '); $objDrawing->setdescription (' Image inserted by Zeal '); $objDrawing->setpath ('./zeali.net.logo.gif ')); $objDrawing->setheight (36); $objDrawing->setcoordinates (' C23 '); $objDrawing->setoffsetx (10); $objDrawing->setrotation (15); $objDrawing->getshadow ()->setvisible (true); $objDrawing->getshadow ()->setdirection (36); $objDrawing->setworksheet ($objActSheet); //Add a new worksheet $objExcel-Createsheet (); $objExcel->getsheet (1)->settitle (' Test 2 '); //Protect Cells $objExcel->getsheet (1)->getprotection ()->setsheet (true); $objExcel->getsheet (1)->protectcells (' A1:c22 ', ' phpexcel ');//Display grid lines:$objPHPExcel->getactivesheet ()->setshowgridlines (true);//Show hidden Columns$objPHPExcel->getactivesheet ()->getcolumndimension (' C ')->setvisible (true);$objPHPExcel->getactivesheet ()->getcolumndimension (' D ')->setvisible (false);//Show hidden rows$objPHPExcel->getactivesheet ()->getrowdimension (' Ten ')->setvisible (false);//Default Column width$objPHPExcel->getactivesheet ()->getdefaultcolumndimension ()->setwidth (12);//Default line width$objPHPExcel->getactivesheet ()->getdefaultrowdimension ()->setrowheight (15);//Worksheet default style settings (and default different settings required separately)$objPHPExcel->getactivesheet ()->getdefaultstyle ()->getfont ()->setname (' Arial ');$objPHPExcel->getactivesheet ()->getdefaultstyle ()->getfont ()->setsize (8);$objPHPExcel->getactivesheet ()->getdefaultstyle ()getalignment ();$objPHPExcel->getactivesheet ()->getdefaultstyle ()->getalignment ()->sethorizontal (phpexcel_style_alignment::horizontal_center); $objPHPExcel->getactivesheet ()->getdefaultstyle ()->getalignment ()->setvertical (phpexcel_style_alignment::vertical_center);//Output Content $outputFileName= "Output.xls"; //to a file////$objWriter->save ($outputFileName);//or//to the browser Header("Content-type:application/force-download"); Header("Content-type:application/octet-stream"); Header("Content-type:application/download"); Header(' Content-disposition:inline;filename= '.$outputFileName.‘"‘); Header("Content-transfer-encoding:binary"); Header("Last-modified:".)gmdate("D, D M Y h:i:s"). "GMT"); Header("Cache-control:must-revalidate, post-check=0, pre-check=0"); Header("Pragma:no-cache"); $objWriter->save (' Php://output '); ?>