Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods setValuesFromArray and cloneRowFromArray to the TemplateProcessor #670

Merged

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.

None yet

2 participants