Reputation: 141
Now I want set text color for cell in phpexcel into foreach loop. The foreach loop is something like :
$redBold = array(
"font" => array(
"bold" => true,
"color" => array("rgb" => "FF0000"),
),
);
$row = 5;
$count = 0
foreach ($data as $key => $value) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($count++, $row, $value['type']?$value['type']:0);
if ($value['type'] == 1) {
$objPHPExcel->getActiveSheet()->getStyle($count . $row)->applyFromArray($redBold);
}
}
this code is not understand getStyle($count . $row )
because $count . $row
should be A6
... Is there way to set text in this case? Please help!
Upvotes: 1
Views: 1389
Reputation: 212402
What do you get when you concatenate $count . $row
?
getStyle()
expects either a cell reference (e.g. A1
, C3
, IV256
) or a cell range (e.g. A1:C3
, B2:D4
, A2:IV256
etc.
You're simply concatenating two numbers, e.g. 0
and 5
to give 05
which is meaningless in terms of cell references/ranges
You need to convert $count
(which you're using as a column index, to an actual column address before concatenating
$objPHPExcel->getActiveSheet()->getStyle(PHPExcel_Cell::stringFromColumnIndex($count) . $row)->applyFromArray($redBold);
Note also that you're incrementing the column using the post-increment operator before trying to set the style for the cell, so it probably isn't going to give you the cell reference that you want
Upvotes: 3