Phpspreadsheet how to set autoheight for merged cell?

亡梦爱人 提交于 2020-12-06 16:01:30

问题


setWrapText work well for one cell, but not works for merged cell.

Here is the code I use to set autosize for merged cell, but it not works.

$sheet = $spreadsheet->getActiveSheet();
$sheet->fromArray([["1\n1\n2\n\n3\n"],range(1,3),['188196','test']]);
$sheet->mergeCells('A1:D1');
$sheet->getStyle("A1:D1")->getAlignment()->setWrapText(true);

unmerged cell:

merged cell:


回答1:


Maybe you must set a rowhight by calculation. See this article. You could try

$spreadsheet->getActiveSheet()->getRowDimension('10')->setRowHeight(-1);

to get the autoheight value.

-1 is the value of auto height. Means the value will calculated automatically. If you need a number of height. I would suggest to calc the height over the value of the cell. You must do following: Find newlines in the content and multiply them with 12.75 pts (standard height).



来源:https://stackoverflow.com/questions/63858786/phpspreadsheet-how-to-set-autoheight-for-merged-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!