1

I'm trying to use the OpenTBS/TinyButStrong library to replace merge fields in a word document.

We can take a very basic word document like this:

Hello, My Name Is Bob, My Age Is <<BOBAGE>>

Which in word has the following code:

{MERGEFIELD BOBAGE\*MERGEFORMAT}

And my code would be basic:

$TBS = new \clsTinyButStrong();
                            $TBS->PlugIn(TBS_INSTALL,OPENTBS_PLUGIN);
                            $TBS->LoadTemplate($path,OPENTBS_ALREADY_UTF8);
                            $TBS->MergeField('BOBAGE','TEST');
                            $TBS->Show(OPENTBS_FILE,$tmpPath . 'test.docx');

When i open test.docx, the merge field isn't replaced!

It works if i use [bobage] which isn't actually a word merge field! That's not what i expected it to do, that's pretty useless.

Is there a way to replace the actual word merge fields?

Glen Elkins
  • 867
  • 9
  • 30

1 Answers1

0

The instruction ̀$TBS->MergeField() is for merging TBS fields, not Ms Word Mail Merge Fields.

TBS fields are those like [my_field] or [my_block.my_field] in your template.

So your snippet could work if you have a piece of text in your template like [BOBAGE].

By the way, OpenTBS can merges document fields if the type is IF field, but not MERGEFIELD. See the documentation and examples for more details.

Skrol29
  • 5,402
  • 1
  • 20
  • 25