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

我正在尝试在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的边界,但它不起作用。我的表格中没有边框


它事件不能通过添加样式来工作。请帮忙


茅侃侃
浏览 194回答 2
2回答

阿晨1998

在这种情况下,请使用内联 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');

蝴蝶不菲

尝试以最少的更改运行代码,并且全部工作)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');
打开App,查看更多内容
随时随地看视频慕课网APP