<?phprequire_once '. /libs/phpword/phpword.php '; Require_once '. /libs/phpword/phpword/iofactory.php '; Require_once '. /.. /config.php ';//new Word Document$phpword = new Phpword (); $objExcel->getproperties ()->setcreator ("Office 2003 Excel "), $objExcel->getproperties ()->setlastmodifiedby (" Office 2003 Excel "), $objExcel->getproperties ()- >settitle ("Office 2003 XLS Test Document"), $objExcel->getproperties ()->setsubject ("Office 2003 XLS test Document "); $objExcel->getproperties ()->setdescription (" Test document for Office 2003 XLS, generated using PHP Classes. "); $objExcel->getproperties ()->setkeywords ("Office 2003 OPENXML PHP"), $objExcel->getproperties () Setcategory ("Test result file"); $objExcel->setactivesheetindex (0); $objActSheet = $objExcel->getactivesheet () ; $data 1 = Array ();//Content Write $objactsheet->settitle (' AAA ');//Set current Sheet$objactsheet->mergecells (' a1:d1 ');// Merge A1 to D1 cell $objactsheet->setcellvalue (' A1 ', ' hardware configuration information '); $objActSheet->setcellvaLue (' A2 ', ' serial number '), $objActSheet->setcellvalue (' B2 ', $data 1[' Serial_number '); $objActSheet->setcellvalue (' C2 ') , ' Purchase order number '), $objActSheet->setcellvalue (' D2 ', $data 1[' Purchase_number '); $objActSheet->setcellvalue (' A3 ', ' hardware manufacturers '); $objActSheet->mergecells (' b3:d3 '); $objActSheet->setcellvalue (' B3 ', $data 1[' factory ']); $ Objactsheet->setcellvalue (' A4 ', ' Device status '), $objActSheet->setcellvalue (' B4 ', $data 1[' status '); $objActSheet- >setcellvalue (' C4 ', ' arrival time '), $objActSheet->setcellvalue (' D4 ', $data 1[' reach_time '); $objActSheet Setcellvalue (' A5 ', ' hardware configuration '); $objActSheet->mergecells (' b5:d5 '); $objActSheet->setcellvalue (' B5 ', $data 1[' $objActSheet->setcellvalue (' A6 ', ' remarks '), $objActSheet->mergecells (' B6:d6 '); $objActSheet- >setcellvalue (' B6 ', $data 1[' remark ');//Set Default row Height $objactsheet->getdefaultrowdimension ()->setrowheight (20) ; Manually Set line height $objactsheet->getrowdimension (' 5 ')->setrowheight (150); $objActSheet->getrowdimension (' 6 ')->setrowheight (100); Line Wrap $objactshEet->getstyle (' B5 ')->getalignment ()->setwraptext (true); $objActSheet->getstyle (' B6 ') Getalignment ()->setwraptext (TRUE);//Set Border color $arrs = Array (' A ', ' B ', ' C ', ' D '); for ($i =1; $i <30; $i + +) {for ($j =0;$ Jgetstyle ($arrs [$j]. $i)->getborders ()->getallborders ()->setborderstyle (phpexcel_style_border::border_ THIN); $objActSheet->getstyle ($arrs [$j]. $i)->getborders ()->getallborders ()->getcolor ()->setargb (' Ff00bbcc '); $objActSheet->getstyle ($arrs [$j]. $i)->getalignment ()->setvertical (Phpexcel_style_alignment::vertical_ CENTER); }}//sets the width of the column $objactsheet->getcolumndimension (' A ')->setwidth (' A '), $objActSheet->getcolumndimension (' B ')- >setwidth (a), $objActSheet->getcolumndimension (' C ')->setwidth (a), $objActSheet->getcolumndimension (' D ')->setwidth (30);//Set page orientation and scale $objactsheet->getpagesetup ()->setorientation (phpexcel_worksheet_ pagesetup::orientation_portrait); $objActSheet->getpagesetup ()->setpapersize (PHPEXcel_worksheet_pagesetup::P apersize_a4);//Generate Excel Document $excelname = ' AAA '; header (' content-type:application/ Vnd.ms-excel '); Header (' cache-control:max-age=0 '); Header (' content-disposition:attachment; Filename= '. Iconv ("Utf-8", "GBK", $excelName). XLS '); $objWriter = Phpexcel_iofactory::createwriter ($objExcel, ' Excel5 '); $objWriter->save (' php://output ');? >
Example of PHP using Phpexcel Library to generate Excel documents