Amna Ahmed
Amna Ahmed

Reputation: 1964

PHPExcel set column width

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?

Upvotes: 7

Views: 48380

Answers (2)

Rolland
Rolland

Reputation: 687

First, disable autosize:

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

Now, you can set:

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

Upvotes: 12

Mark Baker
Mark Baker

Reputation: 212522

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

Upvotes: 9

Related Questions