PHPExcel:给细胞着色吗? [英] PHPExcel: Coloring the cells?

查看:62
本文介绍了PHPExcel:给细胞着色吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHPExcel在服务器上生成一些工作表.或多或少,它一切正常,但是,当我尝试为某些行着色时(每隔第二行,因此该列表将易于阅读),我得到了有趣的东西:该行被着色为好,但仅在未填充的单元格上数据.充满数据的单元格保持白色.

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.

这是我使用的代码

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

            if($ind == 1)
            {
                $style_header = array(                  
                'fill' => array(
                    'type' => PHPExcel_Style_Fill::FILL_SOLID,
                    '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']);

我在做什么错了?

推荐答案

我看不出有任何错误跳到我身上.是将粗体字体应用于带有文本的单元格,还是会忽略整个样式?如果确实设置了粗体,请尝试翻转数组中填充"和字体"的顺序.不过,我认为那不会有所作为.

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.

您也可以尝试$sheet->getStyle('A$row:D$row')->...,只是为所使用的单元格范围(而不是整行)显式设置样式.

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.

这篇关于PHPExcel:给细胞着色吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆