docx
docx copied to clipboard
Using `new SimpleField('XE "test"')` Breaks Structure
In order to check weither or not https://github.com/dolanmiu/docx/discussions/1541 is possible, I build the following test:
import * as fs from "fs";
import { Bookmark, Document, Packer, Paragraph, SimpleField, TextRun } from "docx";
const doc = new Document({
creator: 'Ludger',
sections: [
{
properties: {},
children: [
new Paragraph({
children: [
new TextRun("This should be the 1st Paragraph."),
],
}),
new Paragraph({
children: [
new TextRun("This is a "),
new TextRun("test"),
new SimpleField('XE "test"'),
new TextRun(". It's one sentence in the 2nd Paragraph."),
],
}),
new Paragraph({
children: [
new TextRun("This should be the 3rd Paragraph."),
],
}),
],
},
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("XE-Example.docx", buffer);
});
The created docx file has everything I wanted, but the order is destroyed:
. It's one sentence in the 2nd Paragraph.TThis should be the 3rd Paragraph.
his should be the 1st Paragraph.
This is a test
Here is the document, renamed to zip
: XE-Example.zip