1

I would like to:

1) set min-width of the cell

On the internet there is some discussion about this , but I find the code not work:

$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(100);

the column size is not expand according to the data size / preset width

2) underline the cell

I am making an account table, so I would like to underline some row

$styleArray = array(
  'borders' => array(
    'bottom' => array(
      'style' => PHPExcel_Style_Border::BORDER_THIN
    )
  )
);

$sheet->getStyle('A1')->applyFromArray($styleArray);

However the underline is not exist, I wonder is it due to the border also count as 1 line? for example , if A1 is underlined, then I need to user A3 for the next row.

Thanks a lot for helping.

Update:

1) set min-width:

From the source code the column is a number instead of string , so I try like this but still no luck

    $excel->getActiveSheet()->getColumnDimensionByColumn(0)->setAutoSize(false);
    $excel->getActiveSheet()->getColumnDimensionByColumn(0)->setWidth('4.42');

2) underline is working now

    $border_bottom = array(
        'borders' => array(
            'bottom' => array(
                'style' => PHPExcel_Style_Border::BORDER_THIN
            )
        )
    );

    $excel->getActiveSheet()->getStyle("7")->applyFromArray($border_bottom);

it works, but just wondering can I underline when set cell instead of hardcode the position: A1:B2 etc...

user782104
  • 13,233
  • 55
  • 172
  • 312

1 Answers1

1

In number 1, you can check this: PHPExcel auto size column width

With regards on your number 2, have you tried to use this? Instead of underlining the cell, you underline the value of the cell.

 $styleArray = array(
          'font' => array(
          'underline' => PHPExcel_Style_Font::UNDERLINE_SINGLE
      )
 );

$objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray($styleArray);
unset($styleArray);

If you want a range of cells to be underlined, instead of:

objPHPExcel->getActiveSheet()->getStyle('A1')->applyFromArray($styleArray);

use:

$objPHPExcel->getActiveSheet()->getStyle('A1:A3')->applyFromArray($styleArray);
Community
  • 1
  • 1
L. Herrera
  • 490
  • 4
  • 13