承接 shadz3rg/php-stamp 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shadz3rg/php-stamp

最新稳定版本:1.0.0

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

Template:

alt tag

<?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:

alt tag

统计信息

  • 总下载量: 141.03k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 166
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 166
  • Watchers: 15
  • Forks: 34
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 未知

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固