参见英文答案 >
Create Word Document using PHP in Linux10个
你有没有办法用PHP和没有COM组件生成doc和docx文件?我尝试过PHPWord,它创建了docx文件,但这些文件无法在OpenOffice中打开,因为它们会导致崩溃.我也尝试过PHPDocx,但是根本没有生成任何文件.
你有没有办法用PHP和没有COM组件生成doc和docx文件?我尝试过PHPWord,它创建了docx文件,但这些文件无法在OpenOffice中打开,因为它们会导致崩溃.我也尝试过PHPDocx,但是根本没有生成任何文件.
看这里:
原文链接:https://www.f2er.com/php/140085.html@L_404_1@
使用HTTP头
In this method you need to format the HTML/PHP page using
Word-friendly CSS and add header information to your PHP script. Make
sure you don’t use external style sheets since everything should be in
the same file.As a result user will be prompted to download a file. This file will
not be 100% “original” Word document,but it certainly will open in MS
Word application. You can use this method both for Unix and Windows
environments.
<?PHP header("Content-type: application/vnd.ms-word"); header("Content-Disposition: attachment;Filename=document_name.doc"); echo "<html>"; echo "<Meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">"; echo "<body>"; echo "<b>My first document</b>"; echo "</body>"; echo "</html>"; ?>