首页 > 解决方案 > 文本溢出会在 phpspreadsheet 中工作吗?

问题描述

我面临的问题是,我无法将单元格值设置为文本溢出(未剪辑或包装)。在 Libre Calc 中,它总是以红色三角形符号隐藏。

我有一个需要动态复制的示例 .xls 表。我成功地使用 Codeigniter 框架中的 PHPSpreadsheet 库生成了相同的 .xls 表。

$spreadsheet = new Spreadsheet();

$sheet = $spreadsheet->getActiveSheet();

$sheet->setTitle('1');

$sheet->getPageSetup()->setOrientation(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::ORIENTATION_LANDSCAPE);
$sheet->getPageSetup()->setPaperSize(\PhpOffice\PhpSpreadsheet\Worksheet\PageSetup::PAPERSIZE_A4);

$query_date = $data['month_selected'].' '.$data['year_selected'];

$date = new DateTime($query_date);

$date->modify('first day of this month');
$firstday= $date->format('n/j/Y');

$date->modify('last day of this month');
$lastday= $date->format('n/j/Y');

$xrow = 1;
$sheet->setCellValue('A' . $xrow, 'Attedence for the Period Beginning From '.$firstday.' TO '.$lastday)->getStyle('I' . $xrow)->applyFromArray($borderArrayRowOther);

当我在 office 365 和 Libre Calc 中看到它时,单元格中的文本总是被隐藏。我需要双击才能完全显示。但我需要它充分展示。

[重叠文本][1]:https ://i.stack.imgur.com/zi3Pj.png

标签: phpcodeigniterphpspreadsheet

解决方案


你必须使用

$spreadsheet->getActiveSheet()->getStyle('A1')->getAlignment()->setWrapText(true);

有关更多信息,请参阅文档

根据本次提交,本提交将自动包含在未来的版本中。

也许你必须/将使用一些自动调整然后看看这段代码


推荐阅读