PHPExcel autoheight string on merged cells w / wrapText

Is there a good way to set automatic row audit in PHP Excel? So far I have seen that you can use a fixed height at which you indicate before how tall your row is. I also saw that you can use autoheight if you are not using merged cells.

PHPExcel - dynamic row height for merged cells

How to set auto height in phpexcel?

These two other questions ask similar questions, but none of them answers. One solution I reviewed is counting the number of words in a cell and wrapping based on this and a range of columns. However, this can open a can of worms.

+6
source share
2 answers

You can also do it as follows

  • Merge the cells you want, for example: A7: C7
  • Copy its context into one cell, for example Z7
  • Set the width of the merged cells in Z7
  • Apply Wrap Text to Z7
  • Make Z7 not visible
+1
source

You can do this with this code:

$width=84; $height=20; $text="abcde..."; $excel->getActiveSheet()->getRowDimension(1)->setRowHeight(ceil(strlen($text)/width)*height); 

'height' in the code has a text string in a cell, not an entire cell.

0
source

All Articles