开发者

PHPExcel: Coloring the cells?

开发者 https://www.devze.com 2023-03-30 18:33 出处:网络
I\'m using the PHPExcel to generate some sheets on my server. More or less it everything works fine, but, when I try to color some rows (every second row, so the list would be easily readable) I get f

I'm using the PHPExcel to generate some sheets on my server. More or less it everything works fine, but, when I try to color some rows (every second row, so the list would be easily readable) I get funny thing: the row is colored ok, but only on cells that are not filled with data. The cells that are filled with data remain white.

Here's code I use

            $ind = ($ind + 1) % 2;

            if($ind == 1)
            {
                $style_header = array(                  
                'fill' => array(
                    'type' => PHPExcel_Style_Fill::FILL_SOLID,
 开发者_Python百科                   'color' => array('rgb'=>'CCC'),
                ),
                'font' => array(
                    'bold' => true,
                )
                );
                $sheet->getStyle($row)->applyFromArray( $style_header );

            }

            $sheet->getCellByColumnAndRow(0, $row)->setValue($item['qty']);
            $sheet->getCellByColumnAndRow(1, $row)->setValueExplicit($item['name']);
            $sheet->getCellByColumnAndRow(2, $row)->setValueExplicit($item['size']);
            $sheet->getCellByColumnAndRow(3, $row)->setValueExplicit($item['color']);

What am I doing wrong?


I don't see anything that jumps out at me as being wrong. Does the bold font get applied to the cells with text or is the entire style being ignored? If the bold does get set, try flipping the order of 'fill' and 'font' within the array. I wouldn't think that should make a difference, though.

You could also try $sheet->getStyle('A$row:D$row')->... as well, just to explicitly set the style for the range of cells you're using instead of the whole row.


here you can get good examples http://bayu.freelancer.web.id/2010/07/16/phpexcel-advanced-read-write-excel-made-simple/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号