问题
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