Comment Processors
Alongside expression replacement, Office-stamper presents the feature of processing comments associated with paragraphs in your .docx template. These comments act as directives for manipulating the template.
How Comment Processors Work
- You add a comment to a paragraph, table row, or other element in your Word document.
- In the comment, you write a special expression that tells Office-stamper what to do with that element.
- When Office-stamper processes the document, it finds these comments and applies the specified operations.
- After processing, the comments are removed from the final document
Default Comment Processors
Office-stamper comes with several built-in comment processors that handle common templating needs:
Headers and Footers
The .docx file format doesn’t permit comments within headers or footers. But there’s a workaround in Office-stamper. If you want to display contents within headers or footers conditionally, or require repetitive elements:
- Craft the expression as you would in a comment.
- Encapsulate it with "#{}".
- Position it at the starting of the paragraph you intend to manipulate.
Example:
#{displayParagraphIf(showPageNumbers)} Page ${pageNumber} of ${totalPages}Error Handling
By default, an exception is thrown if a comment fails to process. However, successfully processed comments are wiped from the document.
You can customize the error handling behavior. See the Troubleshooting section for more details.
Next Steps
- Explore SpEL Functions for additional functionality
- See Custom Settings for configuration options
- Learn about Advanced Features for more complex scenarios
