Question

Can anyone help me how to put borders around in my output arrays in my report in excel using PHPexcel.

I read the documentation but the example is in Static and you need to set the number already.

I want to do is when all arrays is transferred to excel all of them will have borders.

The problem is my current code is not working can anyone help me with this please.

$result = array();

       for ( $n = 1; $n <=35; $n++ ){

        $name = isset($_POST['name'.$n]) ? $_POST['name'.$n] : "";
              if(!$name)
              {
                 continue;
              } 

        $no = 0+$n;
        $aic = isset($_POST['aic'.$n]) ? $_POST['aic'.$n] : "";
        $repcode = isset($_POST['repcode']) ? $_POST['repcode'] : "";
        $optA = isset($_POST['optA'.$n]) ? $_POST['optA'.$n] : "";
        $optB = isset($_POST['optB'.$n]) ? $_POST['optB'.$n] : "";
        $optC = isset($_POST['optC'.$n]) ? $_POST['optC'.$n] : "";
        $optD = isset($_POST['optD'.$n]) ? $_POST['optD'.$n] : "";
        $total = isset($_POST['total'.$n]) ? $_POST['total'.$n] : "";
        $remarks = '';

        $result[] = array(
              $no,
              "PRO13325-".$aic,
              $repcode,
              $name,
              $optA,
              $optB,
              $optC,
              $optD,
              $total,
              $remarks );
        }



$row = 5;
    foreach($result as $rows){
    if (!empty($rows[4])) {
        $borderArray = array(
            'borders' => array(
            'outline' => array(
            'style' => PHPExcel_Style_Border::BORDER_THICK,
            'color' => array('argb' => 'FFFF0000'),
                    ),
                ),
            );
        $objPHPExcel->getActiveSheet()->fromArray($rows, null, 'A' . $row)->applyFromArray($borderArray);
        $row++;
    }
}
Was it helpful?

Solution

$borderArray = array(
    'borders' => array(
        'outline' => array(
            'style' => PHPExcel_Style_Border::BORDER_THICK,
            'color' => array('argb' => 'FFFF0000'),
        ),
    ),
);

$row = 5;
foreach($result as $rows){
    if (!empty($rows[4])) {
        $objPHPExcel->getActiveSheet()->fromArray($rows, null, 'A' . $row);
        $row++;
    }
    $columnCount = count($rows);
}

$objPHPExcel->getActiveSheet()
    ->getStyle('A5:' . PHPExcel_Cell::stringFromColumnIndex($columnCount) . $row-1 )
    ->applyFromArray($borderArray);

OTHER TIPS

Try the following:

$borderArray = array(
  'borders' => array(
    'allborders' => array(
        'style' => PHPExcel_Style_Border::BORDER_THICK,
        'color' => array('argb' => 'FFFF0000')
     )
  )
);

$row = 5;
foreach($result as $rows){
    if (!empty($rows[4])) {
        $objPHPExcel->getActiveSheet()->getStyle('A' . $row)->applyFromArray($borderArray);
        $row++;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top