我有如下的HTML代码:与图像将HTML转换成ms.word
file.html
<body>
<h1>TEST</h1>
<p>this is test</p>
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td><img src="../../../wamp/www/html2doc/SGEPP.jpg"></td>
</tr>
</table>
html2doc.php
<?php
$handle = fopen("doc2html.html","r");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=html2word.doc");
echo $contents;
?>
概率lems:
当我转换它时,我得到html2word.doc,但我只能从html文件中获取所有文本。对于html文件中的图像我无法得到它,它缺少图像。所以我想要得到所有来自html和图像的数据也。我该如何解决这个问题?任何人都可以帮助我,谢谢。
您不能以这种方式将html转换为word文档。您所做的只是输出带有.doc扩展名的html文件,而word会为您解释。编写包含嵌入式图像等的文档文档是一个不平凡的问题。您可能会发现http://www.phplivedocx.org/或http://stackoverflow.com/questions/188452/reading-writing-a-ms-word-file-in-php有帮助。 – mjec
我想添加@mjec注释,您忘记在'img'元素的末尾添加'/' ''是正确的html – shnisaka
如果您可以使用Java,那么您可以使用docx4j将XHTML到DOCX。 – JasonPlutext