我面临的问题是,我无法将单元格值设置为文本溢出(未剪切或换行)。它始终在 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]: /image/zi3Pj.png
最佳答案
你必须使用
$spreadsheet->getActiveSheet()->getStyle('A1')->getAlignment()->setWrapText(true);
有关更多信息,请参阅 documentation .
根据此comit this comit这将自动包含在未来的版本中。
也许您必须/将会使用一些自动调整功能,然后查看 this code .
关于php - 文本溢出可以在 phpspreadsheet 中使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57274505/