Added support for w:fldSimple, including convenience class for simple MailMerge fields

This commit is contained in:
Paul de Groot
2021-05-04 23:38:25 +02:00
parent 7acd9e1fde
commit 85583a3dbd
4 changed files with 66 additions and 2 deletions

View File

@ -0,0 +1,23 @@
// http://www.datypic.com/sc/ooxml/e-w_fldSimple-1.html
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { TextRun } from "./text-run";
class FldSimpleAttrs extends XmlAttributeComponent<{ readonly instr: string }> {
protected readonly xmlKeys = { instr: "w:instr" };
}
export class SimpleField extends XmlComponent {
constructor(instruction: string, cachedValue?: string) {
super("w:fldSimple");
this.root.push(new FldSimpleAttrs({ instr: instruction }));
if (cachedValue !== undefined) {
this.root.push(new TextRun(cachedValue));
}
}
}
export class SimpleMailMergeField extends SimpleField {
constructor(fieldName: string) {
super(` MERGEFIELD ${fieldName} `, `«${fieldName}»`);
}
}