设置表格单元格对齐 - PHPPowerPoint

时间:2015-08-04 12:04:16

标签: 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: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

这似乎可以运行,但对已生成的幻灯片没有任何影响。

非常感谢任何建议!

1 个答案:

答案 0 :(得分:1)

所以这对我有用。

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

$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);

我使用了细胞本身的getActiveParagraph()。