cshaptx4869/html2word
Composer 安装命令:
composer require cshaptx4869/html2word
包简介
html to word
关键字:
README 文档
README
html文件转word格式,欢迎 Star (●'◡'●)
推荐转
.doc格式 如果为.docx格式,本机测试 Microsoft Office 2019 打开会有问题,WPS没问题
安装
composer require cshaptx4869/html2word
实例
html模板文件
图片仅支持 PNG, GIF, JPEG, WEBP 格式,且其地址必须是相对于域名根目录或者直接为网络地址
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>html template</title> <style> .testclass { font-size: 30px; color: #ff0000; } </style> </head> <body> <h1>中文的标题,技术无止境,一直在路上</h1> <p>p是可以分段的. 使用PHP将html转word</p> <p>再分一段 使用PHP将html转word</p> <p>还分一段,下面加个图片</p> <img src="/resource/houtarou.jpg" width="300" height="300"> <br /> <img alt="" class="has" src="https://img2020.cnblogs.com/blog/1215492/202108/1215492-20210805104218704-1239652393.png" style="width: 500px;"> <div class="testclass">class样式样式是否可以</div> <div style="color:#999fff">测试行内样式</div> <a href="https://www.baidu.com">是否去除链接</a> </body> </html>
run.php
Html2WordMaker 和 MhtFileMaker 都可以实现。只是原理稍微不同,前者是直接html写入文件,后者是借助mht再写入文件。
<?php require_once 'vendor/autoload.php'; use Fairy\Html2WordMaker; use Fairy\MhtFileMaker; // 1、保存为文件 Html2WordMaker::getInstance() ->addFile('resource/tpl.html') ->eraseLink() ->fetchImg('http://php.test/html2word') ->makeFile('resource/a.doc'); MhtFileMaker::getInstance() ->addFile('resource/tpl.html') ->eraseLink() ->fetchImg('http://php.test/html2word') ->makeFile('resource/a.doc'); // 2、浏览器下载 Html2WordMaker::getInstance() ->addFile('resource/tpl.html') ->fetchImg('http://php.test/html2word') ->download(); MhtFileMaker::getInstance() ->addFile('resource/tpl.html') ->fetchImg('http://php.test/html2word') ->download();
说明:
addFile(): 添加html模板文件
eraseLink(): 去除a链接
fetchImg(): 填充图片,若没有图片资源则不必调用。如果html模板文件中含没有域名的相对路径,则需在第一个参数中传入对应的域名
makeFile(): 保存为文件
download(): 浏览器下载
cshaptx4869/html2word 适用场景与选型建议
cshaptx4869/html2word 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.01k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2019 年 08 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「word」 「html」 「html2word」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cshaptx4869/html2word 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cshaptx4869/html2word 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cshaptx4869/html2word 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
HTML and form generation
Unofficial port of the Carbone API SDK to Saloon v3
Generate random words and sentences with ease in PHP.
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
Reusable utilities library for Lacus Solutions' packages (type description, HTML escaping, random sequences)
统计信息
- 总下载量: 1.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2019-08-08