1

我正在努力在 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

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

任何建议都非常感谢!

4

1 回答 1

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()。

于 2015-12-14T22:43:18.597 回答