【问题标题】:Set Table Cell Alignment - PHPPowerPoint设置表格单元格对齐 - PHPPowerPoint
【发布时间】:2015-08-04 12:04:15
【问题描述】:

我正在努力在 PHPPowerpoint 中设置单元格的对齐方式,我已经搜索和搜索,但似乎找不到任何东西

这是我的 PHP powerpoint 构建脚本的 sn-p -

$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

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

非常感谢任何建议!

【问题讨论】:

    标签: php phppowerpoint


    【解决方案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()。

    【讨论】:

    • 这真的很有帮助!他们的文档还有一些不足之处。
    猜你喜欢
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-21
    • 2013-10-03
    • 2018-04-22
    相关资源
    最近更新 更多