【问题标题】:Set auto height in PHPExcel not working在 PHPExcel 中设置自动高度不起作用
【发布时间】:2016-09-05 09:52:47
【问题描述】:

我正在使用 PHPExcel 生成 Excel。

所有代码都可以正常工作。但是自动高度代码不起作用。

我试过下面的代码。

在特定行上应用行高

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

对所有行应用行高

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

我也尝试过使用它的自动换行属性。

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

但它给我的结果如下:

注意:在 MS office 工作,不在 Apache open Office 工作和 LibreOffice

【问题讨论】:

  • 设置单元格属性以换行,否则仅靠自动高度是不够的
  • @MarkBaker,我也尝试过自动换行属性和自动高度
  • 你用的是什么作家?
  • 而且行高永远不会适用于单个单元格地址,也不适用于具有指定行的默认行尺寸......$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(-1);$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(-1);
  • @MarkBaker,谢谢,两种方法我都试过了,但还是不行

标签: php yii yii2 phpexcel


【解决方案1】:

刚刚在 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 编写器创建正确包装的输出

【讨论】:

  • 谢谢,但不工作
  • 我仍然不知道你在做什么这与我所做的不同,因为在过去 20 分钟内我每次尝试设置 autoheight 都非常有效.....显示你实际上在做什么!
  • 好吧!它在 MS Excel 中适用于我,那么您测试的是哪个版本的 MS Excel?您还在谈论 Excel 2007 吗?如果您使用 Excel5 Writer,它对您有用吗?
  • LibreOffice 中存在错误时没有,但没有... PHPExcel 以正确的格式写入其输出
猜你喜欢
  • 2018-02-13
  • 1970-01-01
  • 1970-01-01
  • 2014-05-10
  • 1970-01-01
  • 2018-06-03
  • 1970-01-01
  • 2016-04-24
  • 2018-03-12
相关资源
最近更新 更多