Using Phpexcel to Excel column chart _php tutorial

Source: Internet
Author: User
This is accompanied by the effect and code of another turn column chart.

Original PHP Report effect:

Effect after turning into Excel:


<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> vcd4kpha+ul3jz7t6wus6pc9wpgo8cd48chjlignsyxnzpq== "Brush:java;" > GetProperties ()->setcreator ("Xiongchuanliang")->setlastmodifiedby ("Xiongchuanliang")->settitle ("schedule") ; $objActSheet = $objPHPExcel->getactivesheet (); $objActSheet->getcolumndimension (' A ')->setwidth (12); $objActSheet->getcolumndimension (' B ')->setwidth (20); $objActSheet->getcolumndimension (' C ')->setwidth (12); $objActSheet->getcolumndimension (' D ')->setwidth (20); $objActSheet->getcolumndimension (' E ')->setwidth (20); $objActSheet->getcolumndimension (' F ')->setwidth (12); $objActSheet->getcolumndimension (' G ')->setwidth (20); $objActSheet->getcolumndimension (' H ')->setwidth (18); $objActSheet->getcolumndimension (' I ')->setwidth (18); $objActSheet->getcolumndimension (' J ')->setwidth (30); $objActSheet->getcolumndimension (' K ')->setwidth (20); $objActSheet->getrowdimension (1)->setrowheight (30); $objActSheet->getrowdimension (2)->setrowheight (16); $objActSheet->getrowdimension (3)->setrowheight (16); $objActSheet-&Gt;mergecells (' A1:k1 '); $objActSheet->mergecells (' a2:k2 '); $objActSheet->mergecells (' A3:k3 '); Set the center alignment $objActSheet->getstyle (' A1 ')->getalignment ()->sethorizontal (phpexcel_style_alignment:: Horizontal_center); $objActSheet->getstyle (' A2 ')->getalignment ()->sethorizontal (Phpexcel_style_alignment::horizontal_ CENTER); $objActSheet->getstyle (' A3 ')->getalignment ()->sethorizontal (Phpexcel_style_alignment::horizontal_ CENTER); $objFontA 1 = $objActSheet->getstyle (' A1 ')->getfont (); $objFontA 1->setsize (18); $objFontA 1->setbold (TRUE); $sqlSelect = "Select ... From (...) k order by ..... "; $sql = mysql_query ($sqlSelect); $info = Mysql_fetch_array ($sql); $objActSheet->setcellvalue (' A1 ', ' schedules '); if (strlen (Trim ($rent _time_begin)) > 0 && strlen (Trim ($rent _time_end)) > 0) {$objActSheet->setcellva Lue (' A2 ', "(". $rent _time_begin. "~". $rent _time_end. ")"); $Objactsheet->setcellvalue (' A3 ', "(demo)"); $row =4; $objActSheet->setcellvalue (' A '. $row, ' ... '); $objActSheet->setcellvalue (' B '. $row, ' ... '); $objActSheet->setcellvalue (' C '. $row, ' ... '); $objActSheet->setcellvalue (' D '. $row, ' ... '); $objActSheet->setcellvalue (' E '. $row, ' ... '); $objActSheet Setcellvalue (' F '. $row, ' ... '); $objActSheet->setcellvalue (' G '. $row, ' ... '); $objActSheet->setcellvalue (' H '. $ Row, ' ... '); $objActSheet->setcellvalue (' I '. $row, ' ... '); $objActSheet->setcellvalue (' J ' $row, ' ... '); $row = 5; do{$objActSheet->setcellvalue (' A '. $row, $info [' ... ']); $objActSheet->setcellvalue (' B '. $row, $info [' ... ']); $ Objactsheet->setcellvalue (' C '. $row, $info [' ... ']); $objActSheet->setcellvalue (' D '. $row, $info [' ... ']); $objActSheet->setcellvalue (' E '. $row, $info [' ... ']); $objActSheet->setcellvalue (' F '. $row, $info [' ... ']); $objActSheet->setcellvalue (' G '. $row, $info [' ... ']); $objActSheet->setcellvalue (' H '. $row, $info [' ... ']); $objActSheet->setceLlvalue (' I '. $row, $info [' ... ']); $objActSheet->setcellvalue (' J '. $row, $info [' ... ']); Accumulate $tmpstatus respectively = $info [' ... ']; if ($tmpstatus = = ' A ') {$status 1++;} else if ($tmpstatus = = ' B ') {$status 2++;} else if ($tmpstatus = = ' C ') {$status 3++;} else if ($tmpstatus = = ' D ') {$status 4++;} else{$status 0 + +;} $row + +; }while ($info =mysql_fetch_array ($sql));//////////////////////////////////////////////////////////////////////// /for ($currrow = 4; $currrow < $row; $currrow + +) {//Set Border $objActSheet->getstyle (' A '. $currrow)->getborders ()-& Gt;gettop ()->setborderstyle (Phpexcel_style_border::border_thin); $objActSheet->getstyle (' A '. $currrow)->getborders ()->getleft ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' A '. $currrow)->getborders ()->getright ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' A '. $currrow)->getborders ()->getbottom ()->setborderstyle (phpexcel_style_ Border::border_thin); $objACtsheet->getstyle (' B '. $currrow)->getborders ()->gettop ()->setborderstyle (Phpexcel_style_border:: Border_thin); $objActSheet->getstyle (' B '. $currrow)->getborders ()->getleft ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' B '. $currrow)->getborders ()->getright ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' B '. $currrow)->getborders ()->getbottom ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' C '. $currrow)->getborders ()->gettop ()->setborderstyle (Phpexcel_style_border :: Border_thin); $objActSheet->getstyle (' C '. $currrow)->getborders ()->getleft ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' C '. $currrow)->getborders ()->getright ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' C '. $currrow)->getborders ()->getbottom ()->setborderstyle (phpexcel_style_Border::border_thin); $objActSheet->getstyle (' D '. $currrow)->getborders ()->gettop ()->setborderstyle (Phpexcel_style_border :: Border_thin); $objActSheet->getstyle (' D '. $currrow)->getborders ()->getleft ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' D '. $currrow)->getborders ()->getright ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' D '. $currrow)->getborders ()->getbottom ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' E '. $currrow)->getborders ()->gettop ()->setborderstyle (Phpexcel_style_border :: Border_thin); $objActSheet->getstyle (' E '. $currrow)->getborders ()->getleft ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' E '. $currrow)->getborders ()->getright ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' E '. $currrow)->getborders ()->getbottom ()->seTborderstyle (Phpexcel_style_border::border_thin); $objActSheet->getstyle (' F '. $currrow)->getborders ()->gettop ()->setborderstyle (Phpexcel_style_border :: Border_thin); $objActSheet->getstyle (' F '. $currrow)->getborders ()->getleft ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' F '. $currrow)->getborders ()->getright ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' F '. $currrow)->getborders ()->getbottom ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' G '. $currrow)->getborders ()->gettop ()->setborderstyle (Phpexcel_style_border :: Border_thin); $objActSheet->getstyle (' G '. $currrow)->getborders ()->getleft ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' G '. $currrow)->getborders ()->getright ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' G '. $currrow)->getbordERs ()->getbottom ()->setborderstyle (Phpexcel_style_border::border_thin); $objActSheet->getstyle (' H '. $currrow)->getborders ()->gettop ()->setborderstyle (Phpexcel_style_border :: Border_thin); $objActSheet->getstyle (' H '. $currrow)->getborders ()->getleft ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' H '. $currrow)->getborders ()->getright ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' H '. $currrow)->getborders ()->getbottom ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' I '. $currrow)->getborders ()->gettop ()->setborderstyle (Phpexcel_style_border :: Border_thin); $objActSheet->getstyle (' I '. $currrow)->getborders ()->getleft ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' I '. $currrow)->getborders ()->getright ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyLe (' I '. $currrow)->getborders ()->getbottom ()->setborderstyle (Phpexcel_style_border::border_thin); $objActSheet->getstyle (' J '. $currrow)->getborders ()->gettop ()->setborderstyle (Phpexcel_style_border :: Border_thin); $objActSheet->getstyle (' J '. $currrow)->getborders ()->getleft ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' J '. $currrow)->getborders ()->getright ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' J '. $currrow)->getborders ()->getbottom ()->setborderstyle (phpexcel_style_ Border::border_thin); }/////////////////////////////////////////////bar///////////////////////////////////////////////$row + = 3; $tabInitRow = $row; $objActSheet->setcellvalue (' A '. $row, ' state '); $objActSheet->setcellvalue (' B '. $row, ' total '); $row + +; $objActSheet->setcellvalue (' A '. $row, ' ... '); $objActSheet->setcellvalue (' B '. $row, $status 0); $row + +; $objActSheet->setcellvalue (' A '. $row, '...'); $objActSheet->setcellvalue (' B '. $row, $status 1); $row + +; $objActSheet->setcellvalue (' A '. $row, ' ... '); $objActSheet->setcellvalue (' B '. $row, $status 2); $row + +; $objActSheet->setcellvalue (' A '. $row, ' ... '); $objActSheet->setcellvalue (' B '. $row, $status 3); $row + +; $objActSheet->setcellvalue (' A '. $row, ' ... '); $objActSheet->setcellvalue (' B '. $row, $status 4); $tabLastRow = $row; for ($currrow = $tabInitRow; $currrow <= $tabLastRow; $currrow + +) {//Set Border $objActSheet->getstyle (' A '. $currrow)-& Gt;getborders ()->gettop ()->setborderstyle (Phpexcel_style_border::border_thin); $objActSheet->getstyle (' A '. $currrow)->getborders ()->getleft ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' A '. $currrow)->getborders ()->getright ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' A '. $currrow)->getborders ()->getbottom ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActShEet->getstyle (' B '. $currrow)->getborders ()->gettop ()->setborderstyle (phpexcel_style_border::border_ THIN); $objActSheet->getstyle (' B '. $currrow)->getborders ()->getleft ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' B '. $currrow)->getborders ()->getright ()->setborderstyle (phpexcel_style_ Border::border_thin); $objActSheet->getstyle (' B '. $currrow)->getborders ()->getbottom ()->setborderstyle (phpexcel_style_ Border::border_thin); }//Set The Labels for each data series we want to plot//datatype//cells reference for data//Format code//number of dat Apoints in series//data values//data Marker$dataserieslabels = Array (new Phpexcel_chart_dataseriesvalues (' String ', ' Wo rksheet! $B $ '. $tabInitRow, NULL, 1),//2010); New Phpexcel_chart_dataseriesvalues (' String ', ' worksheet! $C $ ', NULL, 1),////new Phpexcel_chart_ Dataseriesvalues (' String ', ' worksheet! $D $ ', NULL, 1),//2012//Set the x-axis labels//datatype// Cell reference for data//Format code//number of datapoints in series//data values//data marker$tabinitrow + +; $xAxisTi ckvalues = Array (new Phpexcel_chart_dataseriesvalues (' String ', ' worksheet! $A $ '. $tabInitRow. ': $A $ '. $tabLastRow, NULL , 4),//Q1 to Q4);//Set The data values for each data series we want to plot//datatype//Cell reference for data//Form At code//number of datapoints in series//data values//data marker$dataseriesvalues = Array (new Phpexcel_chart_dataseri Esvalues (' number ', ' worksheet! $B $ '. $tabInitRow. ': $B $ '. $tabLastRow, NULL, 4);//Build The dataseries$series = new Phpexcel_chart_dataseries (Phpexcel_chart_dataseries::type_barchart,//PlotType phpexcel_chart_dataseries:: grouping_clustered,//Plotgrouping range (0, COUNT ($dataSeriesValues)-1),//Plotorder $dataseriesLabels,//Plotlabel $ Xaxistickvalues,//plotcategory $dataSeriesValues//Plotvalues);//Set additional dataseries parameters//make it a Hori Zontal bar rather than a vertical column Graph$serieS->setplotdirection (phpexcel_chart_dataseries::D irection_bar);//Set the series in the plot area$plotarea = new Phpexcel_chart_plotarea (NULL, Array ($series));//Set the Chart legend$legend = new Phpexcel_chart_legend (phpexcel_ Chart_legend::P osition_right, NULL, false), $title = new Phpexcel_chart_title (' state Rollup '); $yAxisLabel = new Phpexcel_chart_ Title (' Total number ');//Create The Chart$chart = new Phpexcel_chart (' Chart1 ',//name $title,//title $legend,//Legend $plotare A,//PlotArea true,//Plotvisibleonly 0,//Displayblanksas NULL,//Xaxislabel $yAxisLabel//Yaxislabel);//Set the PO Sition where the chart should appear in the worksheet $tabLastRow + = 2; $chart->settopleftposition (' A '. $tabLastRow); $ta Blastrow + = $chart->setbottomrightposition (' F '. $tabLastRow);//ADD the chart to the worksheet$objactsheet-> Addchart ($chart);////////////////////////////////////////////////////////////////////////////////////////Set Active sheet index to the first sheet, so Excel opens this as the first sheet$objphpexcel->setactivesheetindex (0); $filename = ' Schedule _ '. Date ("Y_m_d"). ". Xlsx ";//Redirect output to a client ' s Web browser (Excel2007) header (' content-type:application/ Vnd.openxmlformats-officedocument.spreadsheetml.sheet ');//header (' Content-disposition:attachment;filename= "'. $ filename. ' "'); devrent.xlsx//////////////////////////////////////////processing Chinese file name garbled problem $ua = $_server["Http_user_agent"]; $encoded _filename = UrlEncode ($filename), $encoded _filename = str_replace ("+", "%20", $encoded _filename); Header (' Content-type:application/octet-stream '), if (Preg_match ("/msie/", $ua)) {header (' content-disposition:attachment; Filename= "'. $encoded _filename. '"');} else if (Preg_match ("/firefox/", $ua)) {header (' content-disposition:attachment; filename*= ' utf8\ ' \ '. $filename. '"');} else {header (' content-disposition:attachment; Filename= '. $filename. '"');} Header (' cache-control:max-age=0 ');//If you ' re serving to IE 9 and then the FOLLowing may Neededheader (' cache-control:max-age=1 ');//If you ' re serving to IE over SSL and then the following could be need Edheader (' Expires:mon, Jul 1997 05:00:00 GMT '); Date in the Pastheader (' last-modified: '. Gmdate (' d, D M Y h:i:s '). ' GMT '); Always Modifiedheader (' Cache-control:cache, Must-revalidate '); Http/1.1header (' pragma:public '); Http/1.0$objwriter = Phpexcel_iofactory::createwriter ($objPHPExcel, ' Excel2007 '); $objWriter Setincludecharts (TRUE); $objWriter->save (' Php://output '); exit;

Mail:xcl_168@aliyun.com

blog:http://blog.csdn.net/xcl168

http://www.bkjia.com/PHPjc/766058.html www.bkjia.com true http://www.bkjia.com/PHPjc/766058.html techarticle This is attached to the effect and code of another turn column chart. Original PHP report effect: The effect of turning into Excel: vcd4kpha+ul3jz7t6wus6pc9wpgo8cd48chjlignsyxnzpq== "Brush:java;" > getProperties ()->setc ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.