简体   繁体   English

无法在表格中添加边框样式(phpword)

[英]cant add border style in table (phpword)

i am trying to add border in my table inside html.我正在尝试在 html 中的表格中添加边框。 below is my code下面是我的代码

$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');

i have assigned a border of 1 but it didnt work.我已经分配了 1 的边界,但它没有用。 there is no border in my table我的桌子上没有边框

it event doesnt work by adding styling.它事件通过添加样式不起作用。 please help请帮忙

tried run your code with minimal changes and all work)尝试以最少的更改和所有工作运行您的代码)

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结果截图

In this case use inline CSS.在这种情况下,请使用内联 CSS。 This how you should do it:你应该这样做:

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');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM