Phpspreadsheet如何为合并的单元格设置自动高度? [英] Phpspreadsheet how to set autoheight for merged cell?
问题描述
setWrapText
适用于一个单元格,但不适用于合并的单元格.
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);
未合并的单元格:
合并单元格:
推荐答案
也许你必须通过计算设置一个 rowhight.请参阅此文章.你可以试试
Maybe you must set a rowhight by calculation. See this article. You could try
$spreadsheet->getActiveSheet()->getRowDimension('10')->setRowHeight(-1);
获取自动高度值.
-1 是自动高度的值.表示该值将自动计算.如果你需要一些高度.我建议计算单元格值的高度.您必须执行以下操作:在内容中找到换行符并将它们乘以 12.75 pts(标准高度).
-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).
这篇关于Phpspreadsheet如何为合并的单元格设置自动高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!