Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
设置表格单元格对齐-PHPPowerPoint_Php_Phppowerpoint - Fatal编程技术网

设置表格单元格对齐-PHPPowerPoint

设置表格单元格对齐-PHPPowerPoint,php,phppowerpoint,Php,Phppowerpoint,我正在努力设置PHPPowerpoint中单元格的对齐方式,我搜索了又搜索,似乎什么都找不到 以下是我的PHP powerpoint构建脚本的一个片段- $shape = $currentSlide->createTableShape(14); $shape->setHeight(100); $shape->setWidth(800); $shape->setOffsetX(50); $shape->setOffsetY(200); echo date('H:i:

我正在努力设置PHPPowerpoint中单元格的对齐方式,我搜索了又搜索,似乎什么都找不到

以下是我的PHP powerpoint构建脚本的一个片段-

$shape = $currentSlide->createTableShape(14);
$shape->setHeight(100);
$shape->setWidth(800);
$shape->setOffsetX(50);
$shape->setOffsetY(200);

echo date('H:i:s') . ' Add Header Row'.EOL;
$row = $shape->createRow()->setHeight(15);
$row->nextCell()->setWidth(75)->createTextRun('')->getFont()->setBold(true)->setSize(11);
$row->nextCell()->setColSpan(6)->createTextRun('Tests')->getFont()->setBold(true)->setSize(11);

$row->getCell()->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_BOTTOM); // trying to set alignment here

$row->nextCell()->createTextRun('');
$row->nextCell()->createTextRun('');
$row->nextCell()->createTextRun('');
$row->nextCell()->createTextRun('');
$row->nextCell()->createTextRun('');
$row->nextCell()->setColSpan(6)->createTextRun('Long Tests')->getFont()->setBold(true)->setSize(11);
$row->nextCell()->createTextRun('');
$row->nextCell()->createTextRun('');
$row->nextCell()->createTextRun('');
$row->nextCell()->createTextRun('');
$row->nextCell()->createTextRun('');
$row->nextCell()->setWidth(75)->createTextRun('XTests')->getFont()->setBold(true)->setSize(11);
我已尝试将对齐方式设置为与单元格的文本创建内联,如下所示-

 $row->nextCell()->setColSpan(6)->createTextRun('Tests')->getFont()->setBold(true)->setSize(11)->getCell()->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_BOTTOM);
这会抛出一个错误,说字体类中不存在对齐,公平地说,它不存在,但我似乎无法以任何更好的方式进入对齐

其次,我尝试在单元格中创建文本后直接包含对齐代码-

$row->getCell()->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_BOTTOM); // trying to set alignment here
这似乎在运行,但对已生成的幻灯片没有任何影响


非常感谢您的建议

所以这对我有效

我编辑的每个单元格都为其创建了一个变量:

$cellA1 = $row-> nextCell(); //a1 is the address it would have in an excel sheet
然后我为textRun本身创建了一个变量:

$textRunA1 = $cellA1 -> createTextRun('PAGE');//Page is what will be printed in the cell A1
从那里我添加了我的风格:

$textRunA1 -> getFont() -> setBold(true);
$textRunA1 -> getFont() -> setSize(12);
$textRunA1 -> getFont() -> setColor(new Color('FFFFFFFF'));
之后,我把这个放进去,以获得正确的对中:

$cellA1 -> getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_BOTTOM);

我使用了单元格本身的getActiveParagation()。

这真的很有帮助!他们的文档有点不尽如人意。