使用PHP生成word文档

发布于 2024-10-01 17:20:33 字数 187 浏览 1 评论 0原文

您知道使用 PHP 且无需 COM 组件生成 docdocx 文件的方法吗?我尝试过使用 PHPWord 创建 docx 文件,但这些文件无法在 OpenOffice 中打开,因为它们会导致崩溃。我也尝试过 PHPDocx,但它根本没有生成任何文件。

Do you know any way to generate doc and docx files with PHP and without COM component? I've tried PHPWord, which creates docx files, but these cannot be opened in OpenOffice because they cause it to crash. I've also tried PHPDocx, but it didn't generate any files at all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

残月升风 2024-10-08 17:20:33

OpenTBS可以使用模板技术以纯PHP生成Docx文档。

简单的。

OpenTBS can generate Docx documents in pure PHP, using the technique of templates.

Simple.

怂人 2024-10-08 17:20:33

使用 JS 生成 Word 文档:

我创建了一个简单的开源库,它将用值替换标签。

例如,带有 data={name:"John"}Hi {name} 将替换为 Hi John

这是: https://github.com/edi9999/docxtemplater

演示:https://docxtemplater.com/demo

Generating word documents with JS:

I have created a simple open-source library that will replace tags by values.

For example Hi {name} with data={name:"John"} will be replaced by Hi John.

Here it is : https://github.com/edi9999/docxtemplater

Demo: https://docxtemplater.com/demo

浪荡不羁 2024-10-08 17:20:33

请参阅此处:

http://www.webcheatsheet.com/php/create_word_excel_csv_files_with_php.php

引用文章中最常用的方法:

Using HTTP Headers

在此方法中,您需要使用以下命令格式化 HTML/PHP 页面
Word 友好的 CSS 并将标头信息添加到您的 PHP 脚本中。制作
确保您不使用外部样式表,因为所有内容都应该在
相同的文件。

因此,系统将提示用户下载文件。该文件将
不是 100%“原始”Word 文档,但它肯定会在 MS 中打开
字应用。您可以在 Unix 和 Windows 上使用此方法
环境。

<?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>";
?>

See here:

http://www.webcheatsheet.com/php/create_word_excel_csv_files_with_php.php

To quote from the article the most common method:

Using HTTP Headers

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>";
?>
彩扇题诗 2024-10-08 17:20:33

正如我在这里提到的 PHP 转换Word 文件到 HTML 而不丢失样式和图像

到目前为止我找到的最佳解决方案是 http:// /www.phplivedocx.org/ 。您可以将它与 Zend 框架一起使用。设置非常简单,并且与实际单词格式的偏差最小。它可以很好地生成 Word 文档并将其转换为 html(以及其他格式)。

As I mentioned here PHP Convert Word file to HTML without losing styling and images,

The best solution I've found so far is http://www.phplivedocx.org/ . You use it with the Zend framework. Very easy to set up and you get minimal deviation from the actual word format. It generates and converts word docs from/to html (among other formats) very well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文