The colors exported by phpexcel to excel are inconsistent with the colors displayed on the web page_PHP Tutorial

WBOY
Release: 2016-07-21 15:14:44
Original
978 people have browsed it

Regarding some issues with the colors exported by phpexcel, why are the colors of excel exported using phpexcel inconsistent with the colors displayed on the web page? Want to know what's going on? How should we solve it? The PHP code details are as follows:
PHP code:

Copy code The 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");
//查 处理 数据===+++++++++++++++++++++++++++++++++++++++++++++
$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();
$title1 = client_status;
$title2 = fin_confirm;
$title3 = oid;
//去除数组中相同的值
foreach($re as $key => $val){
if(true){
foreach($val as $key2 => $val2){
if(!in_array($key2,$jq)){
$jq[] = $key2;
}
}
}
}
$arr_keys=array();
foreach($re as $k=>$v){
foreach($v as $k2=>$v2){
$arr_keys[]=$k2;
}
}
$c=array_count_values($arr_keys);
//++===++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 创建一个处理对象实例
$objExcel = new PHPExcel();
// 创建文件格式写入对象实例, uncomment
$objWriter = new PHPExcel_Writer_Excel5($objExcel);
//设置文档基本属性/**It seems that it is generally not used**/
$objProps = $objExcel->getProperties();
$objProps->setCreator("杨本木");
$objProps->setLastModifiedBy("杨本木");
$objProps->setTitle("杨本木");
$objProps->setSubject("杨本木");
$objProps->setDescription("杨本木");
$objProps->setKeywords("杨本木");
$objProps->setCategory("杨本木");
//***************************************
//Set the current sheet index for subsequent use Content operations.
//Generally, display calls are only needed when using multiple sheets.
//By default, PHPExcel will automatically create the first sheet with SheetIndex=0
$objExcel->setActiveSheetIndex(0);
$objActSheet = $objExcel->getActiveSheet() ;
//Set the name of the current active sheet
$objActSheet->setTitle('current sheetname');
//Set the width. This value is different from that in EXCEL. I don’t know what the unit is. Slightly smaller than the width in EXCEL
//$objActSheet->getColumnDimension('A')->setWidth(20);
//$objActSheet->getRowDimension(1)->setRowHeight(30) ); //Height
//Set the value of the cell
$objActSheet->setCellValue('A1', 'Total title display');
/*
//Set the style
$objStyleA1 = $objActSheet->getStyle('A1');
$objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objFontA1 = $objStyleA1->getFont ();
$objFontA1->setName('宋体');
$objFontA1->setSize(18);
$objFontA1->setBold(true);
//Set Column center alignment
$objActSheet->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
*/
//============first===================================
$benmu=1;
$objActSheet->setCellValue('A1', '行标签列标签');
foreach($jq as $k=>$v){
$objActSheet->setCellValue(get_excel_row($benmu).'1', $v);
$benmu+=1;
}
$objActSheet->setCellValue(get_excel_row($benmu).'1', '总计');
//设置宽度
for($i=0;$i<$benmu+1;$i++){
$objActSheet->getColumnDimension(get_excel_row($i))->setWidth(20);
//宽度
$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);
//颜色
$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 $k1=>$v1){ //$k1全部放在A2。。。。Later, k1 is the phone number, v1 is the person-》Number
$objActSheet->setCellValue('A'.$y, $k1);
//Color
$objActSheet->getStyle( 'A'.$y)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objActSheet->getStyle('A'.$y)->getFill()-> getStartColor()->setARGB(COLOR1);
foreach($jq as $k2=>$v2){ //k2 is 0, v2 is person
foreach($v1 as $k3=> $v3){ //$k3 is person, $v3 is the desired value
if($k3==$v2){
//$objActSheet->setCellValue(get_excel_row("1"+$k2 ).$y,$v1[$k3]);
$objActSheet->setCellValueExplicit(get_excel_row("1"+$k2).$y,$v1[$k3],PHPExcel_Cell_DataType::TYPE_STRING);
}
}
}
$objActSheet->setCellValue(get_excel_row("1"+count($jq)).$y, $num[$k1]);
$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 is 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 define is not displayed correctly in the exported excel as it should be? What is the reason? Why?
Start by defining a red color to see what is displayed, as follows: define(“COLOR1″,”#FF0000″);
But the result shows that the defined blue color appears similar to purple in excel The color is not the color displayed on the page anyway, which is too puzzling. . . . .
Look at this code: $objActSheet->getStyle('A'.$y)->getFill()->getStartColor()->setARGB(COLOR1);
I think it might be ARGB Reason, so try to add two digits 00 in front of the color. I don’t know if this will work. Let’s try the effect first, and the format may be like this argb(128,255,0,0). You can eliminate this problem first, because a is As for the transparency, I found out after testing it that it was indeed a 4-bit color fix that increased transparency.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326231.htmlTechArticleAbout some issues with the colors exported by phpexcel. Why is the color of excel exported using phpexcel inconsistent with the color display on the web page? Woolen cloth? Want to know what's going on? How to solve...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!