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

TemplateProcessor deleteBlock is not working #2581

Open
diantonio85 opened this issue Mar 4, 2024 · 2 comments
Open

TemplateProcessor deleteBlock is not working #2581

diantonio85 opened this issue Mar 4, 2024 · 2 comments

Comments

@diantonio85
Copy link

Describe the Bug

$templateProcessor->deleteBlock is not working with attached DOCX and PHP 8.1 or above

Steps to Reproduce

Please provide a code sample that reproduces the issue.

<?php
require __DIR__ . '/vendor/autoload.php';
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\TemplateProcessor;
[test.docx](https://github.com/PHPOffice/PHPWord/files/14487611/test.docx)

$templateProcessor = new TemplateProcessor($inputFileName);
$templateProcessor->deleteBlock('NASCONDI_SITI', '');

Expected Behavior

I expected sections between NASCONDI_SITI to get deleted , but this is not happening

Current Behavior

Currently only the section on page 2 is getting delete, while on page 1 they are still there

Context

Please fill in your environment information:

  • PHP Version: 8.1
  • PHPWord Version: composer require phpoffice/phpword
@diantonio85
Copy link
Author

It seems $templateProcessor->deleteBlock doesn't work with tables. I found an alternative solution using cloneBlock :

$templateProcessor->cloneBlock('NASCONDI_SITI', 0);

If deleteBlock (and replaceBlock) don't work with tables, it should be mentioned in the docs

@tyler-wright
Copy link

I get a corrupted file whenever I use either deleteBlock or replaceBlock to delete any type of block. Ffunnily enough the cloneBlock method with an argument of '0' actually achieves the deletion without corrupting the file. That means whatever the procedure being used in that method could be applied to deleteBlock or replaceBlock.

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

No branches or pull requests

2 participants