Phpexcel exporting Excel colors and inconsistent color display in Web pages _php tutorial

Source: Internet
Author: User
Some questions about Phpexcel export color, how does the color of Excel exported with phpexcel inconsistent with the color display in the Web page? Want to know what the hell is going on? What should be done to solve it? The PHP code details are as follows:
PHP Code:
Copy CodeThe code is as follows:
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");
Processing Data ===+++++++++++++++++++++++++++++++++++++++++++++
$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 ');
?>

In the above code, the color in the define in the exported Excel does not correctly display the original color? What's the reason? Why is it?
began to define a red look to show what is, as follows: Define ("Color1″," #FF0000 ″);
But the results show that the definition of blue in Excel is similar to the purple color, which is not the color of the page display, it is too confusing ...
Look at this code: $objActSheet->getstyle (' A '. $y)->getfill ()->getstartcolor ()->setargb (COLOR1);
A little thought may be argb reason, so try to put the color front plus two bit 00, I do not know this can not do, try the effect first, and the format may be such ARGB (128,255,0,0), you can first rule out the problem, because a is transparent, and then experiment to know, is indeed a 4-bit fixed color with increased transparency.

http://www.bkjia.com/PHPjc/326231.html www.bkjia.com true http://www.bkjia.com/PHPjc/326231.html techarticle some questions about Phpexcel export color, how does the color of Excel exported with phpexcel inconsistent with the color display in the Web page? Want to know what the hell is going on? How to solve ...

  • 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.