我是 PHP 新手,我需要一些帮助。
我想将 HTML 表发送到另一个 PHP 文件,然后能够使用此信息(特别是我想像 DOC 文件一样下载此信息)。
我已经看过很多关于如何做到这一点的信息。但我还没有看到没有<tbody></tbody>
怎么办。我有一个动态表,因此数据是从数组加载的。顺便说一句,我正在使用 DataTable-jQuery 来做到这一点。
我有以下 HTML 代码:
<form action="sectoresTable.php" method="post">
<table id="sectoresTable">
<thead>
<tr>
<th><b>#</b></th>
<th><b>Numero</b></th>
<th><b>Nombre</b></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<button type="submit" style="margin-top: 20px;">Exportar</button>
</form>
和sectoresTable.PHP
:
<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment; filename=TablaSectores.doc");
echo '';
?>
顺便说一句,要将数据加载到表中,我使用以下脚本:
<script>
$('#sectoresTable').DataTable({
data: arraySectores
});
</script>
总的来说,所有这些都运行良好,我下载了一个文档文件,但没有信息(这是正确的,因为我的 echo 没有打印任何内容。)。
我知道我需要在 HTML 代码中使用 foreach 吗?但实际上,我不确定。
最佳答案
尝试使用api,将动态html表导出到php中的doc文件
http://www.phpclasses.org/package/2763-PHP-Convert-HTML-into-Microsoft-Word-documents.html
关于javascript - 如何使用php将动态html表导出到doc文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31526991/