如何在单元格区域中应用顶部和左侧边框?

时间:2016-06-28 20:21:19

标签: php phpexcel

我对PHPExcel有点新,我试图在单元格范围内仅应用顶部和左边框,每个边框都有不同的颜色。这就是我正在努力实现的目标:

enter image description here

我尝试过:

$style = array(
  'borders' => array(
    'top' => array('style' => PHPExcel_Style_Border::BORDER_THIN),
    'left' => array('style' => PHPExcel_Style_Border::BORDER_THIN)
  ),
);

$xls->getActiveSheet()->getStyle($range)->applyFromArray($style);

...

但它没有用。

提前致谢!

1 个答案:

答案 0 :(得分:2)

你想要第一列#red和其他#purple ..

$objPHPExcel->getActiveSheet()->getStyle($range)->getBorders()->getTop()->applyFromArray(
         array(
             'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
             'color' => array(
                 'rgb' => #Purple
             )
         )
 );

左边:

$objPHPExcel->getActiveSheet()->getStyle($range)->getBorders()->getLeft()->applyFromArray(
         array(
             'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
             'color' => array(
                 'rgb' => #Red
             )
         )
 );

或者您可以看到文档...... http://www.cmsws.com/examples/applications/phpexcel/Documentation/API/PHPExcel_Style/PHPExcel_Style_Borders.html#methodapplyFromArray

干杯,