Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel set column width

Tags:

php

phpexcel

I am setting column width for a .csv file using

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

But i cannot see any change in column A's width, what am i doing wrong?

like image 733
Amna Ahmed Avatar asked Aug 20 '12 16:08

Amna Ahmed


2 Answers

First, disable autosize:

$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(false);

Now, you can set:

$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth("50");
like image 158
Rolland Avatar answered Oct 30 '22 17:10

Rolland


Assuming you're using the CSV Writer.

CSV files do not support any formatting, just data, so column width (which is formatting) cannot be applied when you write a CSV file

like image 21
Mark Baker Avatar answered Oct 30 '22 19:10

Mark Baker