search
Homephp教程php手册php创建word文档代码

直接用php创建word文档代码(系统无需安装word软件) 使用方法:首先用$word->start()表示要生成word文件了,然后你可以输出任何的HTML代码,不论是从文件读过来再写到这里,还是直接在这里输出HTML,都没有关系.

等你输出完毕后,用$word->save($path)方法,其中$path是你想 生成的word文件的名称(可以给出完整的路径),当你使用了$word->save() 方法后,这后面的任何输出都和word文件没有关系了,也就是说word的生成 工作就完成了,之后就和你平常使用php的方式一样拉,随便你输出什么东西, 都直接在浏览器里输出,而不会写到word里面去,代码如下:

<?php
class word {
    function start() {
        ob_start();
        print &#39;<html xmlns:o="urn:schemas-microsoft-com:office:office"  
xmlns:w="urn:schemas-microsoft-com:office:word"  
xmlns="http://www.w3.org/tr/rec-html40">&#39;;
    }
    function save($path) {
        print "</html>";
        $data = ob_get_contents();
        ob_end_clean();
        $this->wirtefile($path, $data);
    }
    function wirtefile($fn, $data) {
        $fp = fopen($fn, "wb");
        fwrite($fp, $data);
        fclose($fp);
    }
}
//生成word调用方法
include ("word.php");
$word = new word;
$word->start();


教程网址:

欢迎收藏∩_∩但请保留本文链接。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!