shadz3rg/php-stamp
Composer 安装命令:
composer require shadz3rg/php-stamp
包简介
The XSL-way templating library for MS Office Word DOCX documents.
README 文档
README
PHPStamp is a simple templating engine for XML-based Microsoft Word documents.
Library aims to provide native XML-way of templating for DOCX documents as an alternative to treating its content as a plain text for regex replacing, which has a lot of downsides.
Instead it tries to clean messy WYSIWYG-generated code and create reusable XSL stylesheet from document.
Some additional information:
(EN) https://redd.it/30conp
(RU) https://habr.com/ru/articles/244421/
Features
- Caching XSL template to filesystem for fast document render.
- Track document mode - generate and cache new template if original document was updated.
- Configurable brackets for placeholder tags.
- Basic extension system, which helps to generate content blocks such as Cells or ListItems.
Known Issues
- Values inserted into placeholder tags may be highlighted as incorrect by spellcheck, since library removes language attribute and MS Word tries to check it with system language.
Requirements
Library requires PHP 7.4+ with DOM, XSL, Zip extensions.
Installation
Install with Composer:
composer require shadz3rg/php-stamp
Usage
Source Template
<?php require 'vendor/autoload.php'; use PHPStamp\Templator; use PHPStamp\Document\WordDocument; $cachePath = 'path/to/writable/directory'; $templator = new Templator($cachePath); // Enable debug mode to re-generate template with every render call. // $templator->debug = true; // Enable track mode to generate template with every original document change. // $templator->trackDocument = true; $documentPath = 'path/to/document.docx'; $document = new WordDocument($documentPath); $values = [ 'library' => 'PHPStamp 0.1', 'simpleValue' => 'I am simple value', 'nested' => [ 'firstValue' => 'First child value', 'secondValue' => 'Second child value' ], 'header' => 'test of a table row', 'students' => [ ['id' => 1, 'name' => 'Student 1', 'mark' => '10'], ['id' => 2, 'name' => 'Student 2', 'mark' => '4'], ['id' => 3, 'name' => 'Student 3', 'mark' => '7'] ], 'maxMark' => 10, 'todo' => [ 'TODO 1', 'TODO 2', 'TODO 3' ] ]; $result = $templator->render($document, $values); // Now you can get template result. // 1. HTTP Download $result->download(); // Or // 2. Save to file // $saved = $result->save(__DIR__ . '/static', 'Test_Result1.docx'); // if ($saved === true) { // echo 'Saved!'; // } // Or // 3. Buffer output // echo $result->output();
Result Document
shadz3rg/php-stamp 适用场景与选型建议
shadz3rg/php-stamp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 155.16k 次下载、GitHub Stars 达 167, 最近一次更新时间为 2014 年 10 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「template」 「word」 「docx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shadz3rg/php-stamp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shadz3rg/php-stamp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shadz3rg/php-stamp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Unofficial port of the Carbone API SDK to Saloon v3
Generate random words and sentences with ease in PHP.
Simple ASCII output of array data
E2E Studios PHP Framework adaptation of leafsphp/blade package
Ensolab template project
docx template manipulation class, based on mustache templating language
统计信息
- 总下载量: 155.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 167
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-10-15