微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在使用PHPExcel生成Excel.

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

我试过以下代码.

在特定行上应用行高

$objPHPExcel->getActiveSheet()->getRowDimension('7')->setRowHeight(-1); 

为所有行应用行高

$objPHPExcel->getActiveSheet()->getDefaultRowDimension(1)->setRowHeight(-1);

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

$objPHPExcel->getActiveSheet()
    ->getStyle('B7')
    ->getAlignment()
    ->setWrapText(true);

但它给我的结果如下:

enter image description here

Note : Working in MS office,Not Working in Apache open Office and
LibreOffice

解决方法:

刚刚将以下内容添加到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);

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐