2017 © Pedro Peláez
 

library php-stamp

The XSL-way templating library for MS Office Word DOCX documents.

image

shadz3rg/php-stamp

The XSL-way templating library for MS Office Word DOCX documents.

  • Saturday, April 7, 2018
  • by shadz3rg
  • Repository
  • 16 Watchers
  • 125 Stars
  • 12,793 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 28 Forks
  • 4 Open issues
  • 6 Versions
  • 22 % Grown

The README.md

PHPStamp

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., (*1)

Some additional information:
(EN) https://redd.it/30conp
(RU) https://habr.com/ru/articles/244421/, (*2)

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., (*3)

Requirements

Library requires PHP 7.4+ with DOM, XSL, Zip extensions., (*4)

Installation

Install with Composer:, (*5)

composer require shadz3rg/php-stamp, (*6)

Usage

Template:

alt tag, (*7)

<?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, (*8)

The Versions

07/04 2018

dev-master

9999999-dev https://github.com/shadz3rg/PHPStamp

The XSL-way templating library for MS Office Word DOCX documents.

  Sources   Download

MIT

The Requires

 

by Avatar Oleg
by Oleg Aleksandrovich

template word docx

07/04 2018

0.2.0

0.2.0.0 https://github.com/shadz3rg/PHPStamp

The XSL-way templating library for MS Office Word DOCX documents.

  Sources   Download

MIT

The Requires

 

by Oleg Aleksandrovich

template word docx

07/08 2017

0.1.2

0.1.2.0

A library for true XSL-way templating of XML-based Office documents. Supports MS Word docx.

  Sources   Download

MIT

The Requires

 

by Avatar Oleg

template word docx

26/05 2017

0.1.1

0.1.1.0

A library for true XSL-way templating of XML-based Office documents. Supports MS Word docx.

  Sources   Download

MIT

The Requires

 

by Avatar Oleg

template word docx

03/04 2017

0.1

0.1.0.0

A library for true XSL-way templating of XML-based Office documents. Supports MS Word docx.

  Sources   Download

MIT

The Requires

 

by Avatar Oleg

template word docx

13/10 2014

dev-odt

dev-odt

A library for templating XML based office documents (such as .docx, .odt)

  Sources   Download

The Requires

 

by Avatar Oleg G.