Shrink text to fit cell width

Topics: User Forum
Jun 18, 2008 at 6:33 PM
Is there a way to do this? In Excel 2003, there's an option for this under the Alignment tab of the Format Cells dialog box.
Sep 23, 2009 at 8:32 AM

$objPHPExcel->getActiveSheet()->getStyle('G45')->getAlignment()->setShrinkToFit(true);

 

Use like this...Hope it will work :-)

Sep 24, 2009 at 11:20 AM

Is it possible with Excel5 format ?

Because I can't find a way to make it works :/

Developer
Sep 24, 2009 at 2:26 PM

Shrink-to-fit should be working with Excel5 reader/writer.

$excel = new PHPExcel();
$worksheet = $excel->getActiveSheet();

$worksheet->getCell('A1')->setValue('Hello World');
$worksheet->getStyle('A1')->getAlignment()->setShrinkToFit(true);

$worksheet->getCell('A2')->setValue('Hello World');

$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$writer->save('write.xls');


Result: