在 PHP 中生成 Microsoft Word 文件
我能够生成 Microsoft Word 文件,但我想要表结构中的数据。我在 PHP 中使用了 HTML 表标签,但输出看起来并不令人满意。表中有很多单元格间距和单元格填充,即使我已将它们初始化为零空间。知道如何解决这个问题吗?
这是我的代码
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");
$now_date = date('d-m-Y H:i');
echo "<html>";
echo "<body>";
echo "</body>";
echo "<head>";
echo "<div>Seminarthema:</div>\n";
echo "<div>Termin:$now_date</div>";
echo "<br></br>";
echo "<div style='size:20px;'><h2>Teilnehmerliste</h2></div>";
echo "<table border='1' cellpadding='0' cellspacing='0'>
<tr><th>Name</th><th>Vorname</th><th>Buchungskreis</th><th>Kurs-ID</th><th>Teilgenommen</th></tr>";
$students = $GLOBALS["TYPO3_DB"]->exec_SELECTquery('*','tx_training_Registration','hidden=0 AND deleted=0');
$countstud = $GLOBALS['TYPO3_DB']->sql_num_rows($students);
if($countstud){
while($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($students)){
echo "<tr>";
echo "<td>".utf8_decode($row2['firstname'])."</td>";
echo "<td>".utf8_decode($row2['lastname'])."</td>";
echo "<td>".utf8_decode($row2['companycode'])."</td>";
echo "<td>".utf8_decode($row2['trainingid'])."</td>";
echo "<td>".utf8_decode($row2[' status'])."</td>";
echo "</tr>";
}
}
echo "</table>";
echo "</head>";
echo "</html>";
I am able to generate a Microsoft word file, but I want the data in table structure. I have used an HTML table tag in PHP, but the output does not look satisfactory. In the table are a lot of cellspacing and cellpadding even if I have initialize them to zero space. Any idea how can I solve this?
here goes my code
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=document_name.doc");
$now_date = date('d-m-Y H:i');
echo "<html>";
echo "<body>";
echo "</body>";
echo "<head>";
echo "<div>Seminarthema:</div>\n";
echo "<div>Termin:$now_date</div>";
echo "<br></br>";
echo "<div style='size:20px;'><h2>Teilnehmerliste</h2></div>";
echo "<table border='1' cellpadding='0' cellspacing='0'>
<tr><th>Name</th><th>Vorname</th><th>Buchungskreis</th><th>Kurs-ID</th><th>Teilgenommen</th></tr>";
$students = $GLOBALS["TYPO3_DB"]->exec_SELECTquery('*','tx_training_Registration','hidden=0 AND deleted=0');
$countstud = $GLOBALS['TYPO3_DB']->sql_num_rows($students);
if($countstud){
while($row2 = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($students)){
echo "<tr>";
echo "<td>".utf8_decode($row2['firstname'])."</td>";
echo "<td>".utf8_decode($row2['lastname'])."</td>";
echo "<td>".utf8_decode($row2['companycode'])."</td>";
echo "<td>".utf8_decode($row2['trainingid'])."</td>";
echo "<td>".utf8_decode($row2[' status'])."</td>";
echo "</tr>";
}
}
echo "</table>";
echo "</head>";
echo "</html>";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不考虑创建一个“真正的”Word 文档,而不是“假装 HTML 实际上是 Word”文件。看一下 PHPWord。
Why not consider creating a "real" Word document rather than a "make-believe that HTML is actually Word" file. Take a look at PHPWord.