我目前正在使用PHPExcel,我正在尝试为1个特定行添加一种颜色,我已经阅读Set Background cell color in PHPExcel已经尝试了所有这些选项。没有运气!
也许我做错了什么,但在这里:
//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中的所有行都填充文字,被着色;)
答案 0 :(得分:32)
您无法在PHPExcel中设置一行样式,只能设置一个单元格或一系列单元格
$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的背景填充样式