deno.land / x / docx@8.5.0 / demo / 60-track-revisions.ts

60-track-revisions.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Track Revisions aka. "Track Changes"
import * as fs from "fs";import { AlignmentType, DeletedTextRun, Document, Footer, FootnoteReferenceRun, InsertedTextRun, Packer, PageNumber, Paragraph, ShadingType, Tab, TextRun,} from "docx";
/* For reference, see - https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.insertedrun - https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.deletedrun
The setting `features: { trackRevisions: true }` adds an element `<w:trackRevisions />` to the `settings.xml` file. This specifies that the application shall track *new* revisions made to the existing document. See also https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.trackrevisions
Note that this setting enables to track *new changes* after teh file is generated, so this example will still show inserted and deleted text runs when you remove it.*/
const paragraph = new Paragraph({ children: [ new TextRun("This is a simple demo "), new TextRun({ text: "on how to ", }), new InsertedTextRun({ text: "mark a text as an insertion ", id: 0, author: "Firstname Lastname", date: "2020-10-06T09:00:00Z", }), new DeletedTextRun({ text: "or a deletion.", id: 1, author: "Firstname Lastname", date: "2020-10-06T09:00:00Z", }), ],});
const doc = new Document({ footnotes: { 1: { children: [ new Paragraph({ children: [ new TextRun("This is a footnote"), new DeletedTextRun({ text: " with some extra text which was deleted", id: 0, author: "Firstname Lastname", date: "2020-10-06T09:05:00Z", }), new InsertedTextRun({ text: " and new content", id: 1, author: "Firstname Lastname", date: "2020-10-06T09:05:00Z", }), ], }), ], }, }, features: { trackRevisions: true, }, sections: [ { properties: {}, children: [ paragraph, new Paragraph({ children: [ new TextRun("This is a demo "), new DeletedTextRun({ break: 1, text: "in order", color: "ff0000", bold: true, size: 24, font: { name: "Garamond", }, shading: { type: ShadingType.REVERSE_DIAGONAL_STRIPE, color: "00FFFF", fill: "FF0000", }, id: 2, author: "Firstname Lastname", date: "2020-10-06T09:00:00Z", }), new InsertedTextRun({ text: "to show how to ", bold: false, id: 3, author: "Firstname Lastname", date: "2020-10-06T09:05:00Z", }), new TextRun({ bold: true, children: [new Tab(), "use Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1)], }), new TextRun({ bold: true, text: "And some style changes", revision: { id: 4, author: "Firstname Lastname", date: "2020-10-06T09:05:00Z", bold: false, }, }), ], }), ], footers: { default: new Footer({ children: [ new Paragraph({ alignment: AlignmentType.CENTER, children: [ new TextRun("Awesome LLC"), new TextRun({ children: ["Page Number: ", PageNumber.CURRENT], }), new DeletedTextRun({ children: [" to ", PageNumber.TOTAL_PAGES], id: 4, author: "Firstname Lastname", date: "2020-10-06T09:05:00Z", }), new InsertedTextRun({ children: [" from ", PageNumber.TOTAL_PAGES], bold: true, id: 5, author: "Firstname Lastname", date: "2020-10-06T09:05:00Z", }), ], }), ], }), }, }, ],});
Packer.toBuffer(doc).then((buffer) => { fs.writeFileSync("My Document.docx", buffer);});
docx

Version Info

Tagged at
4 months ago