【问题标题】:cant add border style in table (phpword)无法在表格中添加边框样式(phpword)
【发布时间】:2020-05-18 08:03:36
【问题描述】:

我正在尝试在 html 中的表格中添加边框。下面是我的代码

$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$html = "<table border='1'>
<tr>
<th>name</th>
</tr>
<tr><td>John</td></tr>
</table>";
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html );
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="test.docx"');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('php://output');

我已经分配了 1 的边框,但它没有工作。我的桌子上没有边框

添加样式后,it 事件不起作用。请帮忙

【问题讨论】:

    标签: php css phpword


    【解决方案1】:

    尝试以最少的更改和所有工作运行您的代码)

    require_once __DIR__ . '/vendor/autoload.php';
    
    use PhpOffice\PhpWord\IOFactory;
    use PhpOffice\PhpWord\PhpWord;
    use PhpOffice\PhpWord\Shared\Html;
    
    $phpWord = new PhpWord();
    $section = $phpWord->addSection();
    $html = "<table border='1'>
    <tr>
    <th>name</th>
    </tr>
    <tr><td>John</td></tr>
    </table>";
    Html::addHtml($section, $html);
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment;filename="test.docx"');
    $objWriter = IOFactory::createWriter($phpWord);
    $objWriter->save('php://output');
    

    screenshot of result

    【讨论】:

      【解决方案2】:

      在这种情况下,使用内联 CSS。你应该这样做:

      require_once __DIR__ . '/vendor/autoload.php';
      
      use PhpOffice\PhpWord\IOFactory;
      use PhpOffice\PhpWord\PhpWord;
      use PhpOffice\PhpWord\Shared\Html;
      
      $phpWord = new PhpWord();
      $section = $phpWord->addSection();
      $html = "<table style="border: 1px solid black;">
      <tr>
      <th>name</th>
      </tr>
      <tr><td>John</td></tr>
      </table>";
      Html::addHtml($section, $html);
      header('Content-Type: application/octet-stream');
      header('Content-Disposition: attachment;filename="test.docx"');
      $objWriter = IOFactory::createWriter($phpWord);
      $objWriter->save('php://output');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多