用PHP生成Word文档 [英] Generating word documents with PHP

查看:103
本文介绍了用PHP生成Word文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您知道用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.

推荐答案

查看此处:

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

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

To quote from the article the most common method:

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

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.

结果将提示用户下载文件.该文件将 不是100%的原始" Word文档,但肯定会在MS中打开 Word应用程序.您可以在Unix和Windows上都使用此方法 环境.

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

这篇关于用PHP生成Word文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆