Export files using Phpexcel
Phpexcel exporting MySQL database data
The above article as a reference
The following is the code for the Phpexcel style setting:
<span style= "FONT-SIZE:24PX;" ><?php$dir = DirName (__file__); Require $dir. " /db.php "; Require $dir." /phpexcel.php "; $db = new db ($phpexcel); $objPHPExcel = new Phpexcel (); for ($i =0; $i <3; $i + +) {if ($i >0) {$ Objphpexcel->createsheet ();} $objPHPExcel->setactivesheetindex ($i); $objSheet = $objPHPExcel->getactivesheet (); $objSheet Getcolumndimension (' D ')->setwidth (21); Set column width $objsheet->getcolumndimension (' E ')->setwidth (+), $objSheet->getcolumndimension (' F ') SetWidth, $objSheet->getrowdimension (' 1 ')->setrowheight (80); Set line height $objsheet->getrowdimension (' 2 ')->setrowheight, $objSheet->getdefaultstyle ()->getalignment ()->setvertical (phpexcel_style_alignment::vertical_center)->sethorizontal (PHPExcel_Style_Alignment:: Horizontal_center)///Set Horizontal vertical Center $objsheet->getdefaultstyle ()->getfont ()->setname ("Microsoft Jas Black")->setsize (12) ; Sets the default font size $objsheet->getstyle ("A1:f1")->getfont ()->setsize ()->setbold (true); Title Font $objsheet->gEtstyle (' A1:f1 ')->getfill ()->setfilltype (phpexcel_style_fill::fill_solid)->getstartcolor () Setargb (' FFFF0000 '); Set Title background color $objsheet->getstyle ("A1:f1")->applyfromarray (Getborderstyle ("#66FF99")); Set caption Border $data = $db->getuserinfo (); $j = 1; $objSheet->setcellvalue ("A" $j, "****\n****"); $objSheet GetStyle (' A1 ')->getalignment ()->setwraptext (true); Set line break $objsheet->mergecells ("A". $j. ": F". $j); Merge cell $j++; $objSheet->setcellvalue ("A" $j, "number")->setcellvalue ("B". $j, "login name")->setcellvalue ("C". $j, "nickname ")->setcellvalue (" D ". $j," e-mail ")->setcellvalue (" E ". $j," school ")->setcellvalue (" F ". $j," Last Login Time ") Setcellvalue ("G". $j, "random number"), $j ++;foreach ($data as $key + $value) {# code ... $objSheet->setcellvalue ("A". $j, $ value[' id ')->setcellvalue ("B". $j, $value [' User_login '])->setcellvalue ("C". $j, $value [' user_nicename '])- >setcellvalue ("D". $j, $value [' User_email '])->setcellvalue ("E". $j, $value [' Sch_name '])->setcellvalue ("F" . $j, $value [' Last_login_time '])//Display number Method 1. Specify as String 2. Format//->setcellvalueexplicit ("G". $j, Rand (1000000000,9999999999), Phpexcel_cell_datatype: : type_string);->setcellvalue ("G". $j, Rand (100000000,999999999)); The following shows the number $objsheet->getstyle in text Format (' G '. $j)->getnumberformat ()->setformatcode (phpexcel_style_ Numberformat::format_text); $j + +;}} $objWriter = Phpexcel_iofactory::createwriter ($objPHPExcel, "Excel5");//$objWriter->save ($dir. '/export.xls '); Generate Excel File Browser_export ("Excel5", "Browser_excel03.xls"); Browser output $objwriter->save ("Php://output"), function Browser_export ($type, $filename) {if ($type = = "Excel5") {header ( ' Content-type:application/vnd.ms-excel '); Excel2003}else{header (' Content-type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ');// Excel2007}header (' content-disposition:attachment;filename= '. $filename. '); Header (' cache-control:max-age=0 ');} /** get a different color border */function Getborderstyle ($color) {$styleArray = array (' borders ' = = Array (' outline ' = = Array (' style ') = Phpexcel_styLe_border::border_thick, ' color ' = = Array (' RGB ' = = $color),),), return $styleArray;} </span>
Phpexcel style functions can refer to the programming documentation
For example, the number format we used above shows:
Ctrl + left mouse button open
Code to write well, we just use on the line, or is very convenient, the document has all the setup functions, when needed can be found in the inside.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Phpexcel Style Control