Phpexcel is a good thing, powerful, below this is a phpexcel simple Chinese help manual, lists the various properties, as well as the commonly used methods of operation, each one is illustrated with examples, I hope to help you.
Reference Phpexcel
include ' phpexcel.php '; include ' phpexcel/writer/excel2007.php '; // or include ' phpexcel/writer/excel5.php '; for output. xls
$objPHPExcel New // Create an instance
Set properties for Excel
//Create Person$objPHPExcel->getproperties ()->setcreator ("Maarten Balliauw");//Last modified person$objPHPExcel->getproperties ()->setlastmodifiedby ("Maarten Balliauw");//title$objPHPExcel->getproperties ()->settitle (Office "XLSX Test Document");//Topics$objPHPExcel->getproperties ()->setsubject (Office "XLSX Test Document");//Description$objPHPExcel->getproperties ()->setdescription ("Test document for Office" XLSX, generated using PHP classes.));//Key Words$objPHPExcel->getproperties ()->setkeywords ("Office openxml PHP");//type$objPHPExcel->getproperties ()->setcategory ("Test result file");
You can also use the following method
$objPHPExcel->getproperties ()->setcreator ("CTOs") ->setlastmodifiedby (" CTOs ") ->settitle (" office "XLSX Test Document") ->setsubject ("office XLSX Test Document ") ->setdescription (" Test document for Office "XLSX, generated using PHP classes. " ) ->setkeywords ("Office openxml PHP")
Set the current sheet
$objPHPExcel->setactivesheetindex (0);
Set the title of the sheet
$objPHPExcel->getactivesheet ()->settitle (' simple ');
Set cell width
$objPHPExcel->getactivesheet ()->getcolumndimension (' A ')->setwidth (20);
Set cell height
$objPHPExcel->getactivesheet ()->getrowdimension ($i)->setrowheight (40);
Merge cells
$objPHPExcel->getactivesheet ()->mergecells (' A18:e22 ');
Split Cells
$objPHPExcel->getactivesheet ()->unmergecells (' a28:b28 ');
Set up a protection cell to protect the worksheet
$objPHPExcel->getactivesheet ()->getprotection ()->setsheet (true$ Objphpexcel->getactivesheet ()->protectcells (' A3:e13 ', ' phpexcel ');
Set format
$objPHPExcel->getactivesheet ()->getstyle (' E4 ')->getnumberformat ()->setformatcode (phpexcel _style_numberformat::format_currency_eur_simple); $objPHPExcel $objPHPExcel->getactivesheet ()->getstyle (' E4 '), ' e5:e13 ');
Set Bold
$objPHPExcel->getactivesheet ()->getstyle (' B1 ')->getfont ()->setbold (true);
Set the horizontal alignment (horizontal_right,horizontal_left,horizontal_center,horizontal_justify)
$objPHPExcel->getactivesheet ()->getstyle (' D11 ')->getalignment ()->sethorizontal (phpexcel_style_ Alignment::horizontal_right);
Set Vertical Center
$objPHPExcel->getactivesheet ()->getstyle (' A18 ')->getalignment ()->setvertical (phpexcel_ Style_alignment::vertical_center);
Set Font size
$objPHPExcel->getactivesheet ()->getdefaultstyle ()->getfont ()->setsize (10);
Set border
$objPHPExcel
Set Border color
$objPHPExcel->getactivesheet ()->getstyle (' D13 ')->getborders ()->getleft ()->getcolor ()->setargb (' FF993300 ');$objPHPExcel->getactivesheet ()->getstyle (' D13 ')->getborders ()->gettop ()->getcolor ()->setargb (' FF993300 ');$objPHPExcel->getactivesheet ()->getstyle (' D13 ')->getborders ()->getbottom ()->getcolor ()->setargb (' FF993300 ');$objPHPExcel->getactivesheet ()->getstyle (' E13 ')->getborders ()->gettop ()->getcolor ()->setargb (' FF993300 ');$objPHPExcel->getactivesheet ()->getstyle (' E13 ')->getborders ()->getbottom ()->getcolor ()->setargb (' FF993300 ');$objPHPExcel->getactivesheet ()->getstyle (' E13 ')->getborders ()->getright ()->getcolor ()->setargb (' FF993300 ‘);
Inserting images
$objDrawing=Newphpexcel_worksheet_drawing ();/*set the picture path remember: only local pictures*/ $objDrawing->setpath (' Image address ');/*Set Picture height*/ $objDrawing->setheight (180);//Photo Height$objDrawing->setwidth (150);//Photo Width/*set the cell for the picture to insert*/$objDrawing->setcoordinates (' E2 '); /*format the cell where the picture is located*/$objDrawing->setoffsetx (5);$objDrawing->setrotation (5);$objDrawing->getshadow ()->setvisible (true);$objDrawing->getshadow ()->setdirection (50);$objDrawing->setworksheet ($objPHPExcel->getactivesheet ());
Set cell background color
$objPHPExcel->getactivesheet (0)->getstyle (' A1 ')->getfill ()->setfilltype (\phpexcel_style_ Fill::fill_solid); $objPHPExcel->getactivesheet (0)->getstyle (' A1 ')->getfill ()->getstartcolor ()->setargb (' Ffcae8ea ');
Last input browser, export Excel
$savename= ' Export Excel sample ';$ua=$_server["Http_user_agent"];$datetime=Date(' y-m-d ', Time()); if(Preg_match("/msie/",$ua)) { $savename=UrlEncode($savename);//processing IE export name garbled} //Excel Header ParametersHeader(' Content-type:application/vnd.ms-excel '); Header(' Content-disposition:attachment;filename= '.$savename.‘. XLS "');//date is the file name suffixHeader(' Cache-control:max-age=0 '); $objWriter= \phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel5 ');//excel5 to XLS format, excel2007 to xlsx format$objWriter->save (' php://output ');
Phpexcel notes, phpexcel Chinese help manual