思路参考:https://www.it1352.com/1745868.html,如下所示:
You can also do it like this
- Merge cells you want, for example: A7:C7
- Copy context of it to one cell for instance Z7
- Set the width of the merged cells to Z7
- Apply Wrap Text to the Z7
- Make Z7 not visible
脚本实现:
$objActSheet->getColumnDimension('A')->setWidth(26); for($i=1;$i<14;$i++){ $objActSheet->getColumnDimension($col_name[$i])->setWidth(17); } $objActSheet->getColumnDimension('Z')->setWidth(43); $objActSheet->getStyle('A:Z')->getAlignment()->setWrapText(true); //Adaptive line feed ...... $objActSheet->setCellValue('Z'.$current_row,$val); $objActSheet->getColumnDimension('Z')->setVisible(false); ......