php PHPExcel 如何应用文本对齐水平填充 - PHPExcel_Style_Alignment::HORIZONTAL_Fill
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17422855/
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
PHPExcel how to apply text alignment horizontal fill - PHPExcel_Style_Alignment::HORIZONTAL_Fill
提问by user2428524
I'm using PHPExcel to create an excel doc... trying to set the cells text alignment horizontal to fill
我正在使用 PHPExcel 创建一个 excel 文档...试图将单元格文本对齐水平设置为填充
$this->objPHPExcel->getDefaultStyle()
->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_Fill);
tried to add to Alignment.php the option but that didn't work
试图将选项添加到 Alignment.php 中,但这没有用
const HORIZONTAL_Fill = 'fill';
thanks!
谢谢!
回答by Rogerio de Moraes
Valid Alignment Styles
有效的对齐样式
Horizontal alignment stylesCan you use : HORIZONTAL_LEFT = 'left', HORIZONTAL_RIGHT = 'right', HORIZONTAL_CENTER = 'center', HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous' and HORIZONTAL_JUSTIFY = 'justify'.
水平对齐样式您可以使用: HORIZONTAL_LEFT = 'left', HORIZONTAL_RIGHT = 'right', HORIZONTAL_CENTER = 'center', HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous' and HORIZONTAL_JUSTIFY = 'justify'.
Vertical alignment stylesCan you use : VERTICAL_BOTTOM = 'bottom', VERTICAL_TOP = 'top', VERTICAL_CENTER = 'center', VERTICAL_JUSTIFY = 'justify' and HORIZONTAL_GENERAL = 'general'.
垂直对齐样式您可以使用:VERTICAL_BOTTOM = 'bottom', VERTICAL_TOP = 'top', VERTICAL_CENTER = 'center', VERTICAL_JUSTIFY = 'justify' and HORIZONTAL_GENERAL = 'general'.
回答by Mark Baker
I think the constant you're looking for is
我认为你正在寻找的常数是
PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY
all the constants that are available for PHPExcel_Style_Alignment can be found defined at the top of the PHPExcel/Style/Alignment.php file
PHPExcel_Style_Alignment 可用的所有常量都可以在 PHPExcel/Style/Alignment.php 文件的顶部找到
回答by Ravi Gohil
Try this, it worked for me.
试试这个,它对我有用。
$objPHPExcel->getActiveSheet()->getStyle('A11')->getAlignment()->applyFromArray(
array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_FILL)
);
回答by Manish Prajapati
For the PHPOffice newer version (Laravel 5.* Syntax)
对于 PHPOffice 较新版本(Laravel 5.* 语法)
use PhpOffice\PhpSpreadsheet\Style\Alignment;
$style = array(
'alignment' => array(
'horizontal' => Alignment::HORIZONTAL_CENTER,
)
);
$activeSheet->getStyle("A1:D1")->applyFromArray($style);