Skip to content

Few Issues with PHPWord #1889

@jaydjohno

Description

@jaydjohno

PHP Word has been amazing for what i need to achieve, however there is a few issues that i have noticed a few other people have had but i can't seem to figure out how to fix.

I am using the templates processing, and anything to to do with blocks doesn't work, i am attempting a delete block, replace block and also a cloneblock. None of them sem to work.

Here is my code

if (in_array($country, $eu_countries)) 
{
$invoiceProcessor->replaceBlock('VAT', 'VAT: ' . get_post_meta($payment->ID ) );
}
 else
{
$invoiceProcessor->deleteBlock('VAT');
} 

Here is the template tag

${VAT}
This should be deleted replaced.
${/VAT}

Does nothing.

I then have a for loop that creates a cloneblock based on a count, i even removed this and tried to do it manually but still doesn't work.

$standardProcessor->cloneBlock('CLONEME', 3);

This is my block

${CLONEME}
${audio_file}
${/CLONEME}

and i replace the value inside with this:

$standardProcessor->setValue( 'audio_file' , $item['name'], 1 );

Again the value will be replaced with the count but thie audio file is replaced but the block isn't cloned, no matter which way i try to set it up. Is this an issue with the blocks processor.

The other issue i have is when converting my finished .docx to PDF the formatitng is all messed up, i am using DOMPDF, but this doesn't keep the same formatting if it is converted, whats the best way of converting the template to PDF without breaking the format.

thanks for your help

Jay

Activity

mrcnpdlk

mrcnpdlk commented on Jul 20, 2020

@mrcnpdlk

to delete try $standardProcessor->cloneBlock('CLONEME', 0);

davidbaselj

davidbaselj commented on Sep 3, 2021

@davidbaselj

@mrcnpdlk Thank you for you answer. This actually works without modifying library

added this to the 1.3.0 milestone on Aug 18, 2024
modified the milestones: 1.3.0, 1.3.1 on Sep 1, 2024
modified the milestones: 1.4.0, 1.5.0 on Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Progi1984@davidbaselj@mrcnpdlk@jaydjohno

        Issue actions

          Few Issues with PHPWord · Issue #1889 · PHPOffice/PHPWord