使用 PHP 将 html 转换为 word /excel / PowerPoint
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3590646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert html to word /excel / powerPoint with PHP
提问by randomwebdev
How to convert html to word /excel / powerpoint with PHP ?
如何使用 PHP 将 html 转换为 word/excel/powerpoint?
回答by Nick
Try the following PHP classes:
尝试以下 PHP 类:
I only used PHPExcel so far but it worked great and is easy to learn. Since all classes are from the same company I assume that they should fit your needs as well.
到目前为止,我只使用过 PHPExcel,但效果很好,而且很容易学习。由于所有课程都来自同一家公司,我认为它们也应该适合您的需求。
回答by shamittomar
PHP to Word:
PHP 到 Word:
I think the easiest way to generate DOC files with PHP is using the Zend Framework component phpLiveDocx. You can load Word or Open Office templates, merge textual data and save the final document to a number of formats, such as DOC, DOCX, RTF and PDF.
我认为使用 PHP 生成 DOC 文件的最简单方法是使用Zend Framework 组件 phpLiveDocx。您可以加载 Word 或 Open Office 模板、合并文本数据并将最终文档保存为多种格式,例如 DOC、DOCX、RTF 和 PDF。
回答by Blomersi
I agree that @Nick answer is correct, but you do not need an external tool to do what you need, at least not for Word.
我同意@Nick 的答案是正确的,但是您不需要外部工具来完成您需要的操作,至少对于 Word 而言不需要。
To generate a Word document simply add this code at the top of the page you want to convert.
要生成 Word 文档,只需在要转换的页面顶部添加此代码即可。
<?php
header("Content-Type: application/vnd.ms-word");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=MyReport.doc");
?>
For Excel I found this (did not test):
对于 Excel,我发现了这个(没有测试):
<?php
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=abc.xls");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
?>