为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
茅侃侃 2022-09-03 14:47:29
我正在尝试在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的边界,但它不起作用。我的表格中没有边框它事件不能通过添加样式来工作。请帮忙
查看完整描述

2 回答

?
阿晨1998

TA贡献2037条经验 获得超6个赞

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


查看完整回答
反对 回复 2022-09-03
?
蝴蝶不菲

TA贡献1810条经验 获得超4个赞

尝试以最少的更改运行代码,并且全部工作)


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


查看完整回答
反对 回复 2022-09-03
  • 2 回答
  • 0 关注
  • 193 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信