【问题标题】:phpWord - Tables with borders in headers/footersphpWord - 在页眉/页脚中有边框的表格
【发布时间】:2015-06-26 12:44:11
【问题描述】:

我正在使用 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...'));

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

谢谢!

【问题讨论】:

    标签: php phpword


    【解决方案1】:

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

    $table = $header->addTable('My Custom Style');
    

    【讨论】:

    • $header->addTable(array(--my style parameters--)); 成功了。 :-)
    猜你喜欢
    • 2018-08-03
    • 1970-01-01
    • 2021-02-26
    • 2015-08-24
    • 1970-01-01
    • 1970-01-01
    • 2017-05-25
    • 2018-07-06
    • 2012-12-31
    相关资源
    最近更新 更多