nguyenhiep/docxfindandreplace

Find and replace variables in a DOCX template.

2.0.0 2020-12-21 04:37 UTC

This package is auto-updated.

Last update: 2024-04-23 16:01:02 UTC


README

This is a simple find and replace utility for DOCX files. Simple way to take a DOCX template, map some variables, and save a new copy.

Installation

Via Composer

$ composer require nguyenhiep/docxfindandreplace

Usage

In your DOCX template you will need to wrap any variables you would like to replace with curly braces (e.g. firstname). You can use regex expressions as key

\Nguyenhiep\DocxFindAndReplace\Docx::create(__DIR__ . "/template.docx")->replace(
    [
        "firstname"                                         => "nguyen",
        "lastname"                                          => "hiep",
        "/[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+.[a-zA-Z]{2,4}/" => "nguyenhiepvan.bka@gmail.com"
    ]
)->save(__DIR__ . '/newfile.docx');