phpWord - 页眉/页脚中带边框的表格

时间:2015-06-26 12:44:12

标签: php phpword

我正在使用phpWord并对页眉/页脚内容进行更改给我带来了真正的困难。我正在尝试的是将标题内容排列在表格中。该表是通过我编写的代码创建的。但是我尝试应用于放置在标题中的表格的样式不会生效。

以下是我的代码的一部分,我可能会犯错误。

$phpWordObj = new PhpWord();
    $section = $phpWordObj->addSection();

    $styleTable = array('borderSize' => 18, 'borderColor' => '006699');
    $phpWordObj->addTableStyle('My Custom Style', $styleTable);

    //ADD HEADER TO DOCUMENT
    $header = $section->addHeader();
    $header->firstPage();
    $table = $header->addTable();
    $table->addRow();
//logo
    $table->addCell(2000)->addImage(
        '../vendor/phpoffice/phpword/samples/resources/PhpWord.png',
        array('width' => 80, 'height' => 80, 'align' => 'left')
    ); //logo
    $cell = $table->addCell(7000);
    $textrun = $cell->addTextRun();
    $textrun->addText(htmlspecialchars('Custom Name goes here...'));

    $headerGen = $section->addHeader();
    $tableGenHeader = $headerGen->addTable();
    $tableGenHeader->addRow();
//logo
    $tableGenHeader->addCell(2000)->addImage(
        '../vendor/phpoffice/phpword/samples/resources/PhpWord.png',
        array('width' => 80, 'height' => 80, 'align' => 'left')
    );  
    $cellGenHeader = $tableGenHeader->addCell(7000);
    $textrunGenHeader = $cellGenHeader->addTextRun();
    $textrunGenHeader->addText(htmlspecialchars('Custom Name goes here...'));

我想要的只是边框出现,以便标题内容可以相互区分。

谢谢!

1 个答案:

答案 0 :(得分:1)

$ phpWordObj-> addTableStyle(...)添加了一个新表格样式,您需要在表格添加中引用它(即它不是全局定义)。将样式名称作为参数添加到addTable调用应该可以解决这个问题:

pip install artemis-ml
相关问题