2 回答
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');
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');
- 2 回答
- 0 關注
- 258 瀏覽
添加回答
舉報
