我正在使用 PHPExcel 创建一个 excel 文档...试图将单元格文本对齐水平设置为填充
$this->objPHPExcel->getDefaultStyle()
->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_Fill);
试图将选项添加到 Alignment.php,但没有奏效
const HORIZONTAL_Fill = 'fill';
谢谢!
有效的对齐方式
水平对齐样式您可以使用: HORIZONTAL_LEFT = 'left', HORIZONTAL_RIGHT = 'right', HORIZONTAL_CENTER = 'center', HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous' and HORIZONTAL_JUSTIFY = 'justify'.
垂直对齐样式 您可以使用:VERTICAL_BOTTOM = 'bottom', VERTICAL_TOP = 'top', VERTICAL_CENTER = 'center', VERTICAL_JUSTIFY = 'justify' and HORIZONTAL_GENERAL = 'general'.
我认为你正在寻找的常数是
PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY
所有可用于 PHPExcel_Style_Alignment 的常量都可以在 PHPExcel/Style/Alignment.php 文件的顶部找到
For the PHPOffice newer version (Laravel 5.* Syntax)
use PhpOffice\PhpSpreadsheet\Style\Alignment;
$style = array(
'alignment' => array(
'horizontal' => Alignment::HORIZONTAL_CENTER,
)
);
$activeSheet->getStyle("A1:D1")->applyFromArray($style);
试试这个,它对我有用。
$objPHPExcel->getActiveSheet()->getStyle('A11')->getAlignment()->applyFromArray(
array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_FILL)
);