2022-06-19 02:01:54 +01:00
|
|
|
// Simple example to add comments to a document
|
|
|
|
// Import from 'docx' rather than '../build' if you install from npm
|
|
|
|
import * as fs from "fs";
|
2022-06-22 23:35:46 +01:00
|
|
|
import { Document, Packer, Paragraph, TextRun, CommentRangeStart, CommentRangeEnd, CommentReference } from "../build";
|
2022-06-19 02:01:54 +01:00
|
|
|
|
|
|
|
const doc = new Document({
|
2022-06-22 23:35:46 +01:00
|
|
|
comments: {
|
|
|
|
children: [{ id: 0, author: "Ray Chen", date: new Date(), text: "comment text content" }],
|
|
|
|
},
|
2022-06-19 02:01:54 +01:00
|
|
|
sections: [
|
|
|
|
{
|
|
|
|
properties: {},
|
|
|
|
children: [
|
|
|
|
new Paragraph({
|
|
|
|
children: [
|
|
|
|
new TextRun("Hello World"),
|
2022-06-22 23:35:46 +01:00
|
|
|
new CommentRangeStart(0),
|
2022-06-19 02:01:54 +01:00
|
|
|
new TextRun({
|
|
|
|
text: "Foo Bar",
|
|
|
|
bold: true,
|
|
|
|
}),
|
2022-06-22 23:35:46 +01:00
|
|
|
new CommentRangeEnd(0),
|
2022-06-19 02:01:54 +01:00
|
|
|
new TextRun({
|
2022-06-22 23:35:46 +01:00
|
|
|
children: [new CommentReference(0)],
|
2022-06-19 02:01:54 +01:00
|
|
|
bold: true,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
2022-06-19 13:12:59 +01:00
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
2022-06-19 02:01:54 +01:00
|
|
|
});
|