php PHPExcel 和文本换行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11299663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:13:06  来源:igfitidea点击:

PHPExcel and Text Wrapping

phpmysqldatabasephpexcel

提问by tehlivi

I know that this line of code will make the cell text-wrap:

我知道这行代码将使单元格文本换行:

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

'D1' being the chosen cell.

'D1' 是选定的单元格。

Instead of using this code for every cell I need wrapped, is there a way to make the entire Excel Worksheet automatically wrap everything?

有没有办法让整个 Excel 工作表自动包装所有内容,而不是对我需要包装的每个单元格使用此代码?

Or is there a better practice technique to use for specified columns?

或者是否有更好的实践技术可用于指定的列?

回答by Mark Baker

Apply to a range:

适用于一个范围:

$objPHPExcel->getActiveSheet()->getStyle('D1:E999')
    ->getAlignment()->setWrapText(true); 

Apply to a column

应用于列

$objPHPExcel->getActiveSheet()->getStyle('D1:D'.$objPHPExcel->getActiveSheet()->getHighestRow())
    ->getAlignment()->setWrapText(true); 

回答by james

$objPHPExcel->getDefaultStyle()->getAlignment()->setWrapText(true);

回答by Naitik Shah

Apply to column

应用于列

$highestRow = $$objPHPExcel->getActiveSheet()->getHighestRow();
for ($row = 1; $row <= $highestRow; $row++){
    $sheet->getStyle("D$row")->getAlignment()->setWrapText(true);
}