Skip to content

Conversation

@geraldb-nicat
Copy link
Contributor

Hi there!

First of all many thanks for your great work on this package! :)

I thought it would be a very handy addition to the TemplateProcessor-functionality, if it would be possible to set values and clone rows from arrays as data-sources. Since in many cases the variables to be replaced come in array-form (e.g. from a backend), this would allow for more efficient code.

With this pull-request, the following would be possible:

$replacements = [
    'Name' => 'Somebody someone',
    'Street' => 'Coming-Undone-Street 32'
];
$templateProcessor = new TemplateProcessor('Template.docx');
$templateProcessor->setValuesFromArray($replacements);
$rows = [
    [
        'userId' => 1,
        'userFirstName' => 'James',
        'userName' => 'Taylor',
        'userPhone' => '+1 428 889 773'
    ],
    [
        'userId' => 2,
        'userFirstName' => 'Robert',
        'userName' => 'Bell',
        'userPhone' => '+1 428 889 774'
    ],
    [
        'userId' => 3,
        'userFirstName' => 'Michael',
        'userName' => 'Ray',
        'userPhone' => '+1 428 889 775'
    ]
];
$templateProcessor = new TemplateProcessor('Template.docx');
$templateProcessor->cloneRowFromArray('userId', $rows);

I've also added a corresponding sample-file (Sample_37_TemplateCloneRowFromArray.php) and updated the docs.

Feel free to pull this commit, if you deem it useful.

Best wishes
Gerald

…rocessor-class and update samples and docs accordingly
@troosan troosan merged commit bcfb3e8 into PHPOffice:develop Jan 3, 2019
@troosan troosan added this to the v0.17.0 milestone Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants