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

Replacing bookmarks in word - enhancement to TemplateProcessor #1557

Open
cfales opened this issue Jan 25, 2019 · 3 comments
Open

Replacing bookmarks in word - enhancement to TemplateProcessor #1557

cfales opened this issue Jan 25, 2019 · 3 comments

Comments

@cfales
Copy link

cfales commented Jan 25, 2019

This is:

  • [X ] a feature request / enhancement

Expected Behavior

Ability to replace bookmark values using TemplateProcessor in addition to static text macro placeholders.

Current Behavior

Currently TemplateProcessor only replaces static text placeholder values, but not bookmark fields. I have developed two additional functions/methods to TemplateProcessor to allow it to also replace bookmark values.

Enhancements

Adding two new functions/methods to TemplateProcessor (replaceBookmark and setBookmarkForPart) as provided in the attached file
TemplateProcessor_additions.txt

allows for traditional word bookmark fields to be updated along with static text placeholder macros.

$templateProcessor->setValue($fldname, $value);
$templateProcessor->replaceBookmark($fldname, $value);

Context

  • PHP version: 7
  • PHPWord version: 0.14
@helderneves91
Copy link

Would be awesome!!

@chuckdu21
Copy link

hi,
Great job!
Unfortunately, doesn't work in my code... Don't know why

@mangal1018
Copy link

 I tried to use replaceBookmark function to replace bookmarks but this function is not defined in TemplateProcessor.
 so I used this function setValue to replace bookmark but this doesn't replace anymore.
 please check below my code and can you let me know how I can replace my bookmark in .docx file.
         
    $public_path =  public_path("bookMark.docx");
    $public_path_new =  public_path();
    $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($public_path);
    $templateProcessor->setValue('window10', 'Acme Tech');
    $templateProcessor->saveAs($public_path_new.'/abc.docx');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants