7

I am generating Excel using PHPExcel.

All Code Works Fine.But Auto height code is not Working.

I have tried following code.

Apply row height on specific row

$objPHPExcel->getActiveSheet()->getRowDimension('7')->setRowHeight(-1); 

Apply row height on for all row

$objPHPExcel->getActiveSheet()->getDefaultRowDimension(1)->setRowHeight(-1);

I have also tried word wrap property with it.

$objPHPExcel->getActiveSheet()
    ->getStyle('B7')
    ->getAlignment()
    ->setWrapText(true);

But it give me result as below:

enter image description here

Note : Working in MS office,Not Working in Apache open Office and LibreOffice

Yasin Patel
  • 5,624
  • 8
  • 31
  • 53

1 Answers1

9

Have just added the following to the 01simple.php example

$value = "To be or not to be-that is the question: whether 'tis nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles, and, by opposing, end them."; 
$objPHPExcel->getActiveSheet()->setCellValue('A12', $value); 
$objPHPExcel->getActiveSheet()->getRowDimension(12)->setRowHeight(-1); 
$objPHPExcel->getActiveSheet()->getStyle('A12')->getAlignment()->setWrapText(true);

and this creates correctly wrapped output for both Excel2007 and Excel5 Writers

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • 1
    Thanks,but Not Working – Yasin Patel Sep 05 '16 at 10:32
  • Same as above output – Yasin Patel Sep 05 '16 at 10:33
  • Then give me some clues to help me figure out what is going wrong.... if I can't replicate a problem, then I cannot fix it, and I've been testing this for fifteen minutes now without any problems..... what are you doing that's different to what I'm doing that could cause a problem? – Mark Baker Sep 05 '16 at 10:34
  • Given that you've edited your question, and the picture you posted has been changed, you are actually getting word wrap now.... so edit it again, and show the actual code that you're using – Mark Baker Sep 05 '16 at 10:35
  • dude, i did it first but change for you – Yasin Patel Sep 05 '16 at 10:36
  • i am setting height for row and it is working , just auto height is not working – Yasin Patel Sep 05 '16 at 10:39
  • 1
    I still don't know what your'e doing that is different to what I did, because setting autoheight has worked perfectly every time I've tried in the last 20 minutes..... show what you are actually doing! – Mark Baker Sep 05 '16 at 10:42
  • So are you checking this in MS Excel, or in Open/LibreOffice? – Mark Baker Sep 05 '16 at 11:07
  • I have Checked in Both, but i want to saw you that many coder facing this issue. – Yasin Patel Sep 05 '16 at 11:41
  • So does it work in MS Excel or not? And shoudl the PHPExcel library be responsible for fixing bugs in LibreOffice? – Mark Baker Sep 05 '16 at 11:42
  • 1
    Well! It works for me in MS Excel, so which version of MS Excel are you testing against? Are you still talking about Excel 2007? Does it work for you if you use Excel5 Writer? – Mark Baker Sep 05 '16 at 11:43
  • Sorry,In MS excel now it is working ,but not working in Apache open office and LibreOffice – Yasin Patel Sep 05 '16 at 11:48
  • 2
    [This is a known bug in Open/LibreOffice](http://askubuntu.com/questions/272177/does-anyone-know-how-to-wrap-text-in-a-cell-in-libreoffice-calc) – Mark Baker Sep 05 '16 at 11:50
  • Thank you for your time and effort, is there any solution for it. – Yasin Patel Sep 05 '16 at 11:52
  • 1
    There isn't, not while the bug exists in LibreOffice... PHPExcel writes its output in the correct format – Mark Baker Sep 05 '16 at 11:54
  • ok, update your answer so i can accept it. and other people can know it – Yasin Patel Sep 05 '16 at 12:04
  • @MarkBaker This one works for wrapping single cells in a row. But how can I wrap a cell merged across a row (on which `setRowHeight(-1)` is applied)? – Yogesh Mistry Aug 16 '17 at 13:59
  • @Yogesh Mistry I have the same problem – Tom Sep 06 '17 at 14:38
  • @Mark Baker I need your help. Look at this : https://stackoverflow.com/questions/56469303/how-do-i-make-automatic-height-row-based-on-content-in-the-maatwebsite-version-3 – moses toh Jun 05 '19 at 23:49