phpexcel導(dǎo)出excel的顏色和網(wǎng)頁中的顏色顯示不一致
Jun 13, 2016 am 11:56 AM
關(guān)于phpexcel導(dǎo)出顏色的一些問題,用phpexcel做導(dǎo)出的excel的顏色怎么和網(wǎng)頁中的顏色顯示不一致呢?想要知道到底是怎么回事?應(yīng)該如何來解決呢?PHP代碼細(xì)節(jié)如下:
PHP code:
復(fù)制代碼 代碼如下:
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");
//查 處理 數(shù)據(jù)===+++++++++++++++++++++++++++++++++++++++++++++
$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;
//去除數(shù)組中相同的值
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);
//++===++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// 創(chuàng)建一個(gè)處理對象實(shí)例
$objExcel = new PHPExcel();
// 創(chuàng)建文件格式寫入對象實(shí)例, uncomment
$objWriter = new PHPExcel_Writer_Excel5($objExcel);
//設(shè)置文檔基本屬性/**似乎一般情況下用不到**/
$objProps = $objExcel->getProperties();
$objProps->setCreator("楊本木");
$objProps->setLastModifiedBy("楊本木");
$objProps->setTitle("楊本木");
$objProps->setSubject("楊本木");
$objProps->setDescription("楊本木");
$objProps->setKeywords("楊本木");
$objProps->setCategory("楊本木");
//*************************************
//設(shè)置當(dāng)前的sheet索引,用于后續(xù)的內(nèi)容操作。
//一般只有在使用多個(gè)sheet的時(shí)候才需要顯示調(diào)用。
//缺省情況下,PHPExcel會自動創(chuàng)建第一個(gè)sheet被設(shè)置SheetIndex=0
$objExcel->setActiveSheetIndex(0);
$objActSheet = $objExcel->getActiveSheet();
//設(shè)置當(dāng)前活動sheet的名稱
$objActSheet->setTitle('當(dāng)前sheetname');
//設(shè)置寬度,這個(gè)值和EXCEL里的不同,不知道是什么單位,略小于EXCEL中的寬度
//$objActSheet->getColumnDimension('A')->setWidth(20);
//$objActSheet->getRowDimension(1)->setRowHeight(30); //高度
//設(shè)置單元格的值
$objActSheet->setCellValue('A1', '總標(biāo)題顯示');
/*
//設(shè)置樣式
$objStyleA1 = $objActSheet->getStyle('A1');
$objStyleA1->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objFontA1 = $objStyleA1->getFont();
$objFontA1->setName('宋體');
$objFontA1->setSize(18);
$objFontA1->setBold(true);
//設(shè)置列居中對齊
$objActSheet->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
*/
//============first===================================
$benmu=1;
$objActSheet->setCellValue('A1', '行標(biāo)簽\列標(biāo)簽');
foreach($jq as $k=>$v){
$objActSheet->setCellValue(get_excel_row($benmu).'1', $v);
$benmu+=1;
}
$objActSheet->setCellValue(get_excel_row($benmu).'1', '總計(jì)');
//設(shè)置寬度
for($i=0;$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。。。。后面,k1為電話號碼、v1為person-》數(shù)字
$objActSheet->setCellValue('A'.$y, $k1);
//顏色
$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是0,v2是person
foreach($v1 as $k3=>$v3){ //$k3為person,$v3是要的值
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,"總計(jì)");
//顏色
$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為person
$objActSheet->setCellValue(get_excel_row("1"+$k).$y,$c[$v]);
//顏色
$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);
//顏色
$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);
//===============================
//輸出內(nèi)容
$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');
?>
上面的代碼中,define中的顏色在導(dǎo)出的excel沒有正確顯示出本來應(yīng)該的顏色?是什么原因?為什么呢?
開始定義了一個(gè)紅色看顯示是什么,如下:define(“COLOR1″,”#FF0000″);
但是結(jié)果顯示的是,定義藍(lán)色在excel中顯示為類似于紫色的顏色,反正就不是頁面顯示的那種顏色,太令人費(fèi)解了。。。。。
看這句代碼:$objActSheet->getStyle(‘A'.$y)->getFill()->getStartColor()->setARGB(COLOR1);
有點(diǎn)覺得可能是ARGB原因,故試著把顏色前面加兩位00,我不知道這樣行不行,試試效果先,而且格式也有可能是這樣的argb(128,255,0,0),可以先排除這個(gè)問題,因?yàn)閍是透明度,后來試驗(yàn)了才知道,確實(shí)是增加了透明度的4位定色。

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

If when opening a file that needs to be printed, we will find that the table frame line has disappeared for some reason in the print preview. When encountering such a situation, we must deal with it in time. If this also appears in your print file If you have questions like this, then join the editor to learn the following course: What should I do if the frame line disappears when printing a table in Excel? 1. Open a file that needs to be printed, as shown in the figure below. 2. Select all required content areas, as shown in the figure below. 3. Right-click the mouse and select the "Format Cells" option, as shown in the figure below. 4. Click the “Border” option at the top of the window, as shown in the figure below. 5. Select the thin solid line pattern in the line style on the left, as shown in the figure below. 6. Select "Outer Border"

Excel is often used to process data in daily office work, and it is often necessary to use the "filter" function. When we choose to perform "filtering" in Excel, we can only filter up to two conditions for the same column. So, do you know how to filter more than 3 keywords at the same time in Excel? Next, let me demonstrate it to you. The first method is to gradually add the conditions to the filter. If you want to filter out three qualifying details at the same time, you first need to filter out one of them step by step. At the beginning, you can first filter out employees with the surname "Wang" based on the conditions. Then click [OK], and then check [Add current selection to filter] in the filter results. The steps are as follows. Similarly, perform filtering separately again

With the continuous rise of social media, Douyin, as a popular short video platform, has attracted a large number of users. On Douyin, users can not only show their lives but also interact with other users. In this interaction, emoticons have gradually become an important way for users to express their emotions. 1. How to get Douyin private message emoticons on WeChat? First of all, to get private message emoticons on the Douyin platform, you need to log in to your Douyin account, then browse and select the emoticons you like. You can choose to send them to friends or collect them yourself. After receiving the emoticon package on Douyin, you can long press the emoticon package through the private message interface, and then select the "Add to Emoticon" function. In this way, you can add this emoticon package to Douyin’s emoticon library. 3. Next, we need to add the words in the Douyin emoticon library

In our daily work and study, we copy Excel files from others, open them to add content or re-edit them, and then save them. Sometimes a compatibility check dialog box will appear, which is very troublesome. I don’t know Excel software. , can it be changed to normal mode? So below, the editor will bring you detailed steps to solve this problem, let us learn together. Finally, be sure to remember to save it. 1. Open a worksheet and display an additional compatibility mode in the name of the worksheet, as shown in the figure. 2. In this worksheet, after modifying the content and saving it, the dialog box of the compatibility checker always pops up. It is very troublesome to see this page, as shown in the figure. 3. Click the Office button, click Save As, and then

When processing data, sometimes we encounter data that contains various symbols such as multiples, temperatures, etc. Do you know how to set superscripts in Excel? When we use Excel to process data, if we do not set superscripts, it will make it more troublesome to enter a lot of our data. Today, the editor will bring you the specific setting method of excel superscript. 1. First, let us open the Microsoft Office Excel document on the desktop and select the text that needs to be modified into superscript, as shown in the figure. 2. Then, right-click and select the "Format Cells" option in the menu that appears after clicking, as shown in the figure. 3. Next, in the “Format Cells” dialog box that pops up automatically

In the study of software, we are accustomed to using excel, not only because it is convenient, but also because it can meet a variety of formats needed in actual work, and excel is very flexible to use, and there is a mode that is convenient for reading. Today I brought For everyone: where to set the excel reading mode. 1. Turn on the computer, then open the Excel application and find the target data. 2. There are two ways to set the reading mode in Excel. The first one: In Excel, there are a large number of convenient processing methods distributed in the Excel layout. In the lower right corner of Excel, there is a shortcut to set the reading mode. Find the pattern of the cross mark and click it to enter the reading mode. There is a small three-dimensional mark on the right side of the cross mark.

Most users use Excel to process table data. In fact, Excel also has a VBA program. Apart from experts, not many users have used this function. The iif function is often used when writing in VBA. It is actually the same as if The functions of the functions are similar. Let me introduce to you the usage of the iif function. There are iif functions in SQL statements and VBA code in Excel. The iif function is similar to the IF function in the excel worksheet. It performs true and false value judgment and returns different results based on the logically calculated true and false values. IF function usage is (condition, yes, no). IF statement and IIF function in VBA. The former IF statement is a control statement that can execute different statements according to conditions. The latter

Executing PHP code in a web page requires ensuring that the web server supports PHP and is properly configured. PHP can be opened in three ways: * **Server environment:** Place the PHP file in the server root directory and access it through the browser. * **Integrated Development Environment: **Place PHP files in the specified web root directory and access them through the browser. * **Remote Server:** Access PHP files hosted on a remote server via the URL address provided by the server.
