deno.land / x / docx@8.5.0 / demo / 75-tab-stops.ts

75-tab-stops.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
// Example of using tab stops
import * as fs from "fs";import { Document, HeadingLevel, Packer, Paragraph, TabStopPosition, TabStopType, TextRun } from "docx";
const columnWidth = TabStopPosition.MAX / 4;const receiptTabStops = [ // no need to define first left tab column // the right aligned tab column position should point to the end of column // i.e. in this case // (end position of 1st) + (end position of current) // columnWidth + columnWidth = columnWidth * 2
{ type: TabStopType.RIGHT, position: columnWidth * 2 }, { type: TabStopType.RIGHT, position: columnWidth * 3 }, { type: TabStopType.RIGHT, position: TabStopPosition.MAX },];const twoTabStops = [{ type: TabStopType.RIGHT, position: TabStopPosition.MAX }];
const doc = new Document({ defaultTabStop: 0, sections: [ { properties: {}, children: [ new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("Receipt 001")], }), new Paragraph({ tabStops: twoTabStops, children: [ new TextRun({ text: "To Bob.\tBy Alice.", bold: true, }), ], }), new Paragraph({ tabStops: twoTabStops, children: [new TextRun("Foo Inc\tBar Inc")], }), new Paragraph({ text: "" }), new Paragraph({ tabStops: receiptTabStops,
children: [ new TextRun({ text: "Item\tPrice\tQuantity\tSub-total", bold: true, }), ], }), new Paragraph({ tabStops: receiptTabStops, text: "Item 3\t10\t5\t50", }), new Paragraph({ tabStops: receiptTabStops, text: "Item 3\t10\t5\t50", }), new Paragraph({ tabStops: receiptTabStops, text: "Item 3\t10\t5\t50", }), new Paragraph({ tabStops: receiptTabStops, children: [ new TextRun({ text: "\t\t\tTotal: 200", bold: true, }), ], }), ], }, ],});
const stream = Packer.toStream(doc);stream.pipe(fs.createWriteStream("My Document.docx"));
docx

Version Info

Tagged at
4 months ago