本文介绍了PHPExcel颜色到特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用PHPExcel,并且正在尝试为1个特定行赋予一种颜色,我已阅读,我已经尝试了所有这些选项.没有运气!
I am currently working with PHPExcel and I am trying to give 1 specific row a color, I have read Set Background cell color in PHPExcel already and I have try all of those options. Without luck!
也许我做错了,但是事情就这样了:
Maybe I do something wrong, but here it goes:
//Table
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('B2', 'Beller ')
->setCellValue('D2', 'Beller nummer')
->setCellValue('F2', 'Datum')
->setCellValue('H2', 'ontvanger naam')
->setCellValue('J2', 'ontvanger nummer')
->setCellValue('L2', 'Billing seconds')
->setCellValue('N2', 'Direction')
// array
->setCellValue('B3', 'hi')
->setCellValue('D3', 'hi')
->setCellValue('F3', 'hi')
->setCellValue('H3', 'hi')
->setCellValue('J3', 'ontvanger nummer')
->setCellValue('L3', 'Billing seconds')
->setCellValue('N3', 'Direction');
//Werkt niet }
// breedte + kopstukken dikgedrukt
$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('D2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('F2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('H2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('J2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('L2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('N2')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(15);
$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(15);
$objPHPExcel->getActiveSheet()->getStyle('N2')->applyFromArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => 'E05CC2')
)
)
);
它给我N2着色,但是我希望N中所有用文本填充的行都被着色;)
it gives me N2 colored, but I want all the rows in N filled with text, be colored;)
推荐答案
您无法在PHPExcel中设置行的样式,只能设置单元格或单元格范围的样式
You cannot style a row in PHPExcel, only a cell or a range of cells
$objPHPExcel->getActiveSheet()
->getStyle('A1:E1')
->getFill()
->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
->getStartColor()
->setARGB('FF808080');
或
$objPHPExcel->getActiveSheet()
->getStyle('A1:E1')
->applyFromArray(
array(
'fill' => array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'color' => array('rgb' => 'E05CC2')
)
)
);
将为单元格A1到E1设置背景填充样式
Will set the background fill style for cells A1 to E1
这篇关于PHPExcel颜色到特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!