A
A
Aricus2019-05-10 11:14:04
PHP
Aricus, 2019-05-10 11:14:04

Why are borders not being set in PhpExcel?

I'm using PhpExcel and not PhpSpreadsheet because I couldn't install images in the latter.
I need to set cell borders. Tried different options. Here the red text color is set, but the border is not:

$objReader = new PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load('..\..\control-files\templates\storeconfirm.xlsx');
$objPHPExcel->setActiveSheetIndex(0);
$sheet = $objPHPExcel->getActiveSheet();


      $styleArray = array(
        'font'  => array(
          'bold'  => true,
          'color' => array('rgb' => 'FF0000'),
        ),
        'borders' => array(
          'bottom' => array(
            'borderStyle' => PHPExcel_Style_Border::BORDER_THIN,
            'color' => array('rgb' => '000000')
           ),
          'top' => array(
            'borderStyle' => PHPExcel_Style_Border::BORDER_THIN,
            'color' => array('rgb' => '000000')
          )
        )
      );
      $sheet->getStyle('A'.$coord)->applyFromArray($styleArray);

The option directly from the documentation does not work either:
$objPHPExcel->getActiveSheet()->getStyle('B2')->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_RED);
$objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);

In this case, no errors are produced.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aricus, 2019-05-10
@Aricus

If anyone is interested, another option worked:

$borderStyle = array(
    'borders' => array(
      'allborders' => array(
        'style' => PHPExcel_Style_Border::BORDER_THIN
      )
    )
  );
  $sheet->getStyle('A'.$coord.':J'.$coord)->applyFromArray($borderStyle);

This code draws all the borders inside the interval. Separately, they are drawn somehow differently, but for my purposes this is not necessary if you use cell merging:
$sheet->mergeCells('D'.$coord.':J'.$coord);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question