Cookbook

Clean blocks placeholders

javadocx includes several methods to work with block elements. These elements allow to define regions made of one or more contents in a DOCX, which can be cleaned of placeholders, deleted and cloned.

You can replace any placeholder in a region defined by placeholders. To do it just run the template methods of javadocx or DOCXPath, just like you would do with any other placeholder or content in the document.

The advantage of blocks is that after working with a document you can call the clearBlocks method to delete all placeholders of the block kind, in other words, all $BLOCK_*$ placeholders. The content of these placeholders would be unaltered.

For example, the following code substitutes an existing placeholder in a document inside of a region delimited by blocks. Then the code deletes from template.docx all block placeholders.

Related information