The colors of phpexcel export excel do not match the colors in the web page

  • 2020-05-27 04:35:10
  • OfStack

Some questions about phpexcel exported color 1, how can the color of excel exported with phpexcel be different from the color display in the web page? Want to know what's going on? How to solve it? The PHP code details are as follows:
PHP code:
 
<?php 
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"); 
// check   To deal with   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(); 
$title1 = client_status; 
$title2 = fin_confirm; 
$title3 = oid; 
// Remove the same value from the array  
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); 
//++===++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
//  create 1 Handle object instances  
$objExcel = new PHPExcel(); 
//  Create a file format to write to the object instance , uncomment 
$objWriter = new PHPExcel_Writer_Excel5($objExcel); 
// Sets the document's basic properties /** Seems to be 1 Not normally **/ 
$objProps = $objExcel->getProperties(); 
$objProps->setCreator(" Yang this wooden "); 
$objProps->setLastModifiedBy(" Yang this wooden "); 
$objProps->setTitle(" Yang this wooden "); 
$objProps->setSubject(" Yang this wooden "); 
$objProps->setDescription(" Yang this wooden "); 
$objProps->setKeywords(" Yang this wooden "); 
$objProps->setCategory(" Yang this wooden "); 
//************************************* 
// Set the current sheet Index for subsequent content operations.  
//1 General only in the use of multiple sheet Is required to display the call.  
// By default, PHPExcel It will automatically create a number 1 a sheet Is set SheetIndex=0 
$objExcel->setActiveSheetIndex(0); 
$objActSheet = $objExcel->getActiveSheet(); 
// Set current activity sheet The name of the  
$objActSheet->setTitle(' The current sheetname'); 
// Set the width, the value and EXCEL I don't know what the units are, a little less than EXCEL The width of the  
//$objActSheet->getColumnDimension('A')->setWidth(20); 
//$objActSheet->getRowDimension(1)->setRowHeight(30); // highly  
// Sets the value of the cell  
$objActSheet->setCellValue('A1', ' General heading display '); 
/* 
// Set the style  
$objStyleA1 = $objActSheet->getStyle('A1'); 
$objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); 
$objFontA1 = $objStyleA1->getFont(); 
$objFontA1->setName(' Song typeface '); 
$objFontA1->setSize(18); 
$objFontA1->setBold(true); 
// Set the alignment in the center  
$objActSheet->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); 
*/ 
//============first=================================== 
$benmu=1; 
$objActSheet->setCellValue('A1', ' The line label \ The column tag '); 
foreach($jq as $k=>$v){ 
$objActSheet->setCellValue(get_excel_row($benmu).'1', $v); 
$benmu+=1; 
} 
$objActSheet->setCellValue(get_excel_row($benmu).'1', ' A total of '); 
// Set the width  
for($i=0;$i<$benmu+1;$i++){ 
$objActSheet->getColumnDimension(get_excel_row($i))->setWidth(20); 
// The width of the  
$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 $k1=>$v1){ //$k1 All in A2 . behind ,k1 Is the telephone number, v1 for person- "Digital  
$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 for person,$v3 Is to 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," A total of "); 
// 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 for 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  
$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 does not show the correct color in the exported excel? What's the reason? Why is that?
Start by defining 1 red to see what is displayed, as follows: define(" COLOR1 ", "#FF0000");
But it turns out that the definition of blue in excel is something like purple, which is not what the page looks like anyway, so confusing...
Look at this code: $objActSheet- > getStyle (' A '. $y) - > getFill()- > getStartColor()- > setARGB(COLOR1);
I don't know whether it is ok to add two 00 in front of the color. Try the effect first, and the format may be like argb(128,255,0,0). You can rule out this problem first, because a is transparent.

Related articles: