PHPOffice / PHPWord

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

Replace macros with multiple elements by splitting existing text runs/paragraphs instead of replacing them #2607

Open jensschuppe opened 2 months ago

jensschuppe commented 2 months ago

Description

setComplexValue() can only replace macros with a single OOXML element. #2562 tries to make it support Section elements for inserting a batch of elements (e.g. created from HTML).

This PR is a different approach with a separate method setElementsValue() which receives an array of elements and tries to split the paragraph or text element containing the macro variable instead of replacing it. No new paragraph is added if the replacement is inline-only (Text elements without a TextRun).

Checklist:

coveralls commented 2 months ago

Coverage Status

coverage: 96.803% (-0.4%) from 97.217% when pulling 795f2ecbba65055cf3c8bd39d4adfcd01e81710b on jensschuppe:replaceMacroMultipleElements into 8b891bb6842dd383f679b47898fad0b7c181f325 on PHPOffice:master.