guigrpa / docx-templates

Template-based docx report creation
MIT License
882 stars 145 forks source link

Feature request: Field Codes as alternative to cmdDelimiter characters #365

Closed Amerlander closed 5 months ago

Amerlander commented 5 months ago

I'm searching for ways to improve the ease of use when creating templates.

There is a function in word called Field Codes (STRG+F9 to insert one). I was thinking if it would be possible to use these instead of delimiting characters. Has anyone already thought about this, or are there technical limitations I don't have in mind?

Advantages of Field Codes:

The XML for {ABC} is:

<w:r>
    <w:rPr>
        <w:lang w:val="en-GB"/>
    </w:rPr>
    <w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r>
    <w:rPr>
        <w:lang w:val="en-GB"/>
    </w:rPr>
    <w:instrText xml:space="preserve">
        ABC
    </w:instrText>
</w:r>
<w:r>
    <w:rPr>
        <w:lang w:val="en-GB"/>
    </w:rPr>
    <w:fldChar w:fldCharType="end"/>
</w:r>

Here are two pictures of a regular test template and one with field codes. The cursor is in both inside the “Work Title” field: image image

Amerlander commented 5 months ago

Just found out they disapear as soons as the documents is reopened. Thats intereseting, becouse they are in the XML. But it does not make sense to create templates that cant be edited later I guess.

image