-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
modify-existing-table.test.ts
173 lines (161 loc) · 4.36 KB
/
modify-existing-table.test.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
166
167
168
169
170
171
172
173
import Automizer, { modify, XmlHelper } from '../src/index';
import { TableRow, TableRowStyle } from '../src/index';
test('create presentation, add and modify an existing table.', async () => {
const automizer = new Automizer({
templateDir: `${__dirname}/pptx-templates`,
outputDir: `${__dirname}/pptx-output`,
});
const data1 = {
body: [
<TableRow>{
label: 'item test r1',
values: ['test1', 10, 16, 12, 11],
styles: [
{
border: [
{
tag: 'lnB',
weight: 18500,
type: 'sysDot',
color: {
type: 'srgbClr',
value: 'aacc00',
},
},
{
tag: 'lnR',
weight: 18500,
type: 'sysDot',
color: {
type: 'srgbClr',
value: 'aacc00',
},
},
{
tag: 'lnL',
weight: 18500,
type: 'sysDot',
color: {
type: 'srgbClr',
value: 'aacc00',
},
},
{
tag: 'lnT',
weight: 18500,
type: 'sysDot',
color: {
type: 'srgbClr',
value: 'aacc00',
},
},
],
},
],
},
{ label: 'item test r2', values: ['test2', 12, 18, 15, 12] },
{ label: 'item test r3', values: ['test3', 14, 12, 11, 14] },
],
};
const data2 = {
body: [
{ label: 'item test r1', values: ['test1', 10, 16, 12] },
{ label: 'item test r2', values: ['test2', 12, 18, 15] },
{ label: 'item test r3', values: ['test3', 14, 12, 11] },
{ label: 'item test r4', values: ['test4', 14, 12, 18] },
{ label: 'item test r5', values: ['test5', 14, 13, 15] },
{ label: 'item test r6', values: ['test6', 999, 14, 14] },
{ label: 'item test r7', values: ['test7', 998, 15, 13] },
{ label: 'item test r8', values: ['test8', 997, 16, 19] },
{ label: 'item test r9', values: ['test9', 996, 17, 18] },
],
};
const data3 = {
body: [
<TableRow>{
label: 'item test r1',
values: ['test1', 10, 16],
styles: [
null,
<TableRowStyle>{
color: {
type: 'srgbClr',
value: 'cccccc',
},
size: 1400,
},
],
},
{ label: 'item test r2', values: ['test2', 12, 18] },
{
label: 'item test r3',
values: ['test3', 14, 13],
},
],
};
const data4 = {
body: [
<TableRow>{
label: 'item test r1',
values: ['test1', 12],
styles: [
{
border: [
{
tag: 'lnB',
weight: 35000,
color: {
type: 'srgbClr',
value: 'aacc00',
},
},
],
},
{
border: [
{
tag: 'lnT',
weight: 8500,
type: 'sysDot',
color: {
type: 'srgbClr',
value: 'aacc00',
},
},
{
tag: 'lnR',
weight: 8500,
type: 'sysDot',
color: {
type: 'srgbClr',
value: 'aacc00',
},
},
],
},
],
},
],
};
const pres = automizer
.loadRoot(`RootTemplate.pptx`)
.load(`SlideWithTables.pptx`, 'tables');
const result = await pres
.addSlide('tables', 1, (slide) => {
slide.modifyElement('TableDefault', [modify.setTable(data1)]);
slide.modifyElement('TableWithLabels', [
modify.setTable(data2),
// modify.dump
]);
slide.modifyElement('TableWithHeader', [
modify.setTableData(data3),
modify.adjustHeight(data3),
modify.adjustWidth(data3),
]);
})
.addSlide('tables', 2, (slide) => {
slide.modifyElement('LabelsVertical', [modify.setTable(data4)]);
})
.write(`modify-existing-table.test.pptx`);
// expect(result.tables).toBe(2); // tbd
});