PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, October 5, 2022

[FIXED] How to apply top and left border in a cell range?

 October 05, 2022     php, phpexcel     No comments   

Issue

I am a bit new on PHPExcel and I'm triying to apply only top and left border in a cells range, each border with different colors. This is what I'm triying to achieve:

enter image description here

I tried with:

$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);

...

But it didn't work.

Thanks in advance!


Solution

you want de first column #red and the rest #purple..

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

for the left:

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

Or you can see the documentation... http://www.cmsws.com/examples/applications/phpexcel/Documentation/API/PHPExcel_Style/PHPExcel_Style_Borders.html#methodapplyFromArray

Cheers,



Answered By - Danieldms
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing