- Require_once './phpexcel.php ';
- Require_once './excel5.php ';
- Require_once './get_excel_row.php ';
- Require ". /include/base.php ";
- Require ". /include/function/006/createxceldb.php ";
- Define ("COLOR1", "#96B7F6");
- Data Processing--------------------------
- $q = $db->query ("SELECT * from Oa_event_sales");
- while ($a = $db->fetch_array ($q)) {
- $list [] = $a;
- }
- $ce = new Createxceldb ();
- $re = $ce->_run ($list, ' served_time ', ' client_status ', ' oid ');
- $all _nums=0;
- $num =array ();
- foreach ($re as $k = = $v) {
- $num [$k]=count ($re [$k]);
- $all _nums+=count ($re [$k]);
- }
- $JQ = Array ();
- $title 1 = client_status;
- $title 2 = fin_confirm;
- $title 3 = oid;
- Remove the same value from the array
- foreach ($re as $key = = $val) {
- if (true) {
- foreach ($val as $key 2 = $val 2) {
- if (!in_array ($key 2, $JQ)) {
- $JQ [] = $key 2;
- }
- }
- }
- }
- $arr _keys=array ();
- foreach ($re as $k = = $v) {
- foreach ($v as $k 2=> $v 2) {
- $arr _keys[]= $k 2;
- }
- }
- $c =array_count_values ($arr _keys);
- //++===---------------------------
- Create a Processing object instance
- $objExcel = new Phpexcel ();
- Create a file format to write to an object instance, uncomment
- $objWriter = new Phpexcel_writer_excel5 ($objExcel);
- Set document basic properties/** seems to normally use less than **/
- $objProps = $objExcel->getproperties ();
- $objProps->setcreator ("Yang Benmu");
- $objProps->setlastmodifiedby ("Yang Benmu");
- $objProps->settitle ("Yang Benmu");
- $objProps->setsubject ("Yang Benmu");
- $objProps->setdescription ("Yang Benmu");
- $objProps->setkeywords ("Yang Benmu");
- $objProps->setcategory ("Yang Benmu");
- //*************************************
- 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 (' current sheetname ');
- Set the width, this value is different from Excel, do not know what is the unit, slightly less than the width of Excel
- $objActSheet->getcolumndimension (' A ')->setwidth (20);
- $objActSheet->getrowdimension (1)->setrowheight (30); Height
- Set the value of a cell
- $objActSheet->setcellvalue (' A1 ', ' total title display ');
- /*
- Set style
- $objStyleA 1 = $objActSheet->getstyle (' A1 ');
- $objStyleA 1->getalignment ()->sethorizontal (Phpexcel_style_alignment::horizontal_center);
- $objFontA 1 = $objStyleA 1->getfont ();
- $objFontA 1->setname (' Song-Body ');
- $objFontA 1->setsize (18);
- $objFontA 1->setbold (TRUE);
- Set Column Center alignment
- $objActSheet->getstyle (' D ')->getalignment ()->sethorizontal (Phpexcel_style_alignment::horizontal_ CENTER);
- */
- ---------------First---------------------
- $BENMU = 1;
- $objActSheet->setcellvalue (' A1 ', ' row label \ column label ');
- foreach ($jq as $k = = $v) {
- $objActSheet->setcellvalue (Get_excel_row ($BENMU). ' 1 ', $v);
- $benmu +=1;
- }
- $objActSheet->setcellvalue (Get_excel_row ($BENMU). ' 1 ', ' total ');
- Set width
- for ($i =0; $i < $benmu +1; $i + +) {
- $objActSheet->getcolumndimension (Get_excel_row ($i))->setwidth (20);
- Width
- $objActSheet->getstyle (Get_excel_row ($i). " 1 ")->getalignment ()->sethorizontal (Phpexcel_style_alignment::horizontal_center);
- $objActSheet->getstyle (Get_excel_row ($i))->getalignment ()->sethorizontal (phpexcel_style_alignment:: Horizontal_center);
- Color
- $objActSheet->getstyle (Get_excel_row ($i). " 1 ")->getfill ()->setfilltype (phpexcel_style_fill::fill_solid);
- $objActSheet->getstyle (Get_excel_row ($i). " 1 ")->getfill ()->getstartcolor ()->setargb (COLOR1);
- }
- -------------Content--------------------
- $y = 2;
- foreach ($re as $k 1=> $v 1) {//$k 1 all on A2 .... Back, K1 for phone number, v1 for person-"number
- $objActSheet->setcellvalue (' A '. $y, $k 1);
- Color
- $objActSheet->getstyle (' A '. $y)->getfill ()->setfilltype (phpexcel_style_fill::fill_solid);
- $objActSheet->getstyle (' A '. $y)->getfill ()->getstartcolor ()->setargb (COLOR1);
- foreach ($jq as $k 2=> $v 2) {//k2 is 0,v2 is person
- foreach ($v 1 as $k 3=> $v 3) {//$k 3 is person, $v 3 is the value to be
- if ($k 3== $v 2) {
- $objActSheet->setcellvalue (Get_excel_row ("1" + $k 2). $y, $v 1[$k 3]);
- $objActSheet->setcellvalueexplicit (Get_excel_row ("1" + $k 2). $y, $v 1[$k 3],phpexcel_cell_datatype::type_string);
- }
- }
- }
- $objActSheet->setcellvalue (Get_excel_row ("1" +count ($JQ)). $y, $num [$k 1]);
- $y +=1;
- }
- -----------------Last----------------
- $objActSheet->setcellvalue ("A". $y, "total");
- Color
- $objActSheet->getstyle ("A". $y)->getfill ()->setfilltype (phpexcel_style_fill::fill_solid);
- $objActSheet->getstyle ("A". $y)->getfill ()->getstartcolor ()->setargb (COLOR1);
- foreach ($jq as $k = + $v) {//k as Person
- $objActSheet->setcellvalue (Get_excel_row ("1" + $k). $y, $c [$v]);
- Color
- $objActSheet->getstyle (Get_excel_row ("1" + $k). $y)->getfill ()->setfilltype (Phpexcel_style_fill::fill_ SOLID);
- $objActSheet->getstyle (Get_excel_row ("1" + $k). $y)->getfill ()->getstartcolor ()->setargb (COLOR1);
- }
- $objActSheet->setcellvalue (Get_excel_row ("1" +count ($JQ)). $y, $all _nums);
- Color
- $objActSheet->getstyle (Get_excel_row ("1" +count ($JQ)). $y)->getfill ()->setfilltype (Phpexcel_style_fill: : Fill_solid);
- $objActSheet->getstyle (Get_excel_row ("1" +count ($JQ)). $y)->getfill ()->getstartcolor ()->setargb ( COLOR1);
- //-----------------------------------
- Output content
- $outputFileName =time (). ". XLS ";
- Header ("Pragma:public");
- Header ("expires:0");
- Header ("Cache-control:must-revalidate, Post-check=0, pre-check=0");
- Header ("Content-type:application/force-download");
- Header ("Content-type:application/octet-stream");
- Header ("Content-type:application/download");
- Header (' Content-disposition:attachment;filename= '. $outputFileName. ');
- Header ("Content-transfer-encoding:binary");
- $objWriter->save (' php://output ');
- ?>
Copy CodeThe above code, define colors in the exported Excel does not correctly display the original color. Start by defining a red look at what the display is, as follows: Define ("Color1″," #FF0000 ″); But the result is that the definition blue appears in Excel as a purple-like color, which is not the color of the page display anyway. Look at this code: $objActSheet->getstyle (' A '. $y)->getfill ()->getstartcolor ()->setargb (COLOR1); Consider the probable cause of ARGB, Try to add two digits to the front of the color 00, the format may be such ARGB (128,255,0,0), you can rule out this problem, because a is transparent, after the test is not known, it is indeed increased transparency of the 4-bit color. |