在PHPExcel中设置自动高度不起作用

Yas*_*tel 4 php yii phpexcel yii2

我正在使用PHPExcel生成Excel.

所有代码工作正常.但是自动高度代码不起作用.

我试过以下代码.

在特定行上应用行高

$objPHPExcel->getActiveSheet()->getRowDimension('7')->setRowHeight(-1); 
Run Code Online (Sandbox Code Playgroud)

为所有行应用行高

$objPHPExcel->getActiveSheet()->getDefaultRowDimension(1)->setRowHeight(-1);
Run Code Online (Sandbox Code Playgroud)

我也尝试过自动换行属性.

$objPHPExcel->getActiveSheet()
    ->getStyle('B7')
    ->getAlignment()
    ->setWrapText(true);
Run Code Online (Sandbox Code Playgroud)

但它给我的结果如下:

在此输入图像描述

注意:在MS office工作,不在Apache中运行Office和LibreOffice

Mar*_*ker 7

刚刚将以下内容添加到01simple.php示例中

$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);
Run Code Online (Sandbox Code Playgroud)

这为Excel2007和Excel5 Writer创建了正确的包装输出

  • [这是Open/LibreOffice中的已知错误](http://askubuntu.com/questions/272177/does-anyone-know-how-to-wrap-text-in-a-cell-in-libreoffice-calc) (2认同)