PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.26k stars 2.69k forks source link

Few Issues with PHPWord #1889

Open jaydjohno opened 4 years ago

jaydjohno commented 4 years ago

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

mrcnpdlk commented 4 years ago

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

davidbaselj commented 3 years ago

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