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

Allow reading/replacing mailmerge #1050

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dlwatersuk
Copy link

No description provided.

@dlwatersuk
Copy link
Author

Regex and functions taken from an earlier attempt at adding this I found in the pull requests, little bit of reworking and it looks to work in the use cases I've tested.

@FBnil
Copy link

FBnil commented Oct 21, 2017

@dlwatersuk Very useful, however you should make a subclass, like:
class MailMergeTemplateProcessor extends \PhpOffice\PhpWord\TemplateProcessor { ....
and only put the functions there that you actually change/add, AND name that file MailMergeTemplateProcessor.php. This will make it easier to use both the old and the new class.

Also think broader, you can mailmerge, but actually you are using FIELDS.
http://www.officeopenxml.com/WPfields.php

It also lacks a MailMergeTemplateProcessorTest.php (just look at TemplateProcessorTest.php). It is actually hard work to add that. For example, the specifications say you can have "One or more <w:instrText> elements, which, together, contain a complete field.", so you need a testcase to handle such a fragmented field.

You also do not handle dirty, where you unset that field because you just replaced it, so it is current information, right?
I also think you use way too much code. Cleanup setMailMergeValue() it does nothing at the moment. make a new function for the regexp that you use in many places. Get rid of setMergeData and just add it as a parameter to doMerge. Do not pass $replace[] around, you may understand it, but the code will have to be supported later on, and that could be someone else.
I also see only support for w:fldChar and not fldSimple.

Can you post some information about mailmerging?

@ebuzzz
Copy link

ebuzzz commented Mar 4, 2021

I've been testing this class for a new project. For the most part, it works. But for larger documents, the parseMergeSection function return null, which means the PREG library errored out. In my case it was the PREG_JIT_STACKLIMIT_ERROR error, which must be related to the backtracking that is used in the regex, but I'm unsure where to start.

Wouldn't it be better to just replace all the regex matches and replacements with DomDocument?

@PowerKiKi PowerKiKi changed the base branch from develop to master November 16, 2022 21:11
@Progi1984 Progi1984 force-pushed the master branch 3 times, most recently from 2d9f999 to e458249 Compare August 30, 2023 11:56
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

4 participants