PHP code example of natmars / yii2-word

1. Go to this page and download the library: Download natmars/yii2-word library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

natmars / yii2-word example snippets


use natmars\word\Word;

$templateFullPath = $templatesDir . $fileName;
$outputFullPath = $tmpDir . $fileName;
        
$phpWord = new Word();

// create a file using a template
$phpWord->saveFromMultiLineTemplate($templateFullPath, $outputFullPath, [
    'variableName' => 'variableValue',
    'tableName' => [
        ['itemName' => 'itemValue1'],
        ['itemName' => 'itemValue2'],
        ['itemName' => 'itemValue3'],
    ],
]);

// download file
$phpWord->downloadTemplate($outputFullPath);