Skip to content

Commit bbd4241

Browse files
committed
chore(test): add example for table cell formatting (#77)
1 parent 3493828 commit bbd4241

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import Automizer, { modify, TableData } from '../src/index';
2+
3+
test('Add and modify an existing table, apply styles to cell.', async () => {
4+
const automizer = new Automizer({
5+
templateDir: `${__dirname}/pptx-templates`,
6+
outputDir: `${__dirname}/pptx-output`,
7+
});
8+
9+
const data1: TableData = {
10+
body: [
11+
{
12+
values: ['test1', 10, 16, 12, 11],
13+
styles: [
14+
{
15+
color: {
16+
type: 'srgbClr',
17+
value: '00FF00',
18+
},
19+
background: {
20+
type: 'srgbClr',
21+
value: 'CCCCCC',
22+
},
23+
isItalics: true,
24+
isBold: true,
25+
},
26+
],
27+
},
28+
{ values: ['test2', 12, 18, 15, 12] },
29+
{
30+
values: ['test3', 14, 12, 11, 14],
31+
styles: [
32+
null,
33+
null,
34+
null,
35+
null,
36+
{
37+
color: {
38+
type: 'srgbClr',
39+
value: 'FF0000',
40+
},
41+
background: {
42+
type: 'srgbClr',
43+
value: '333333',
44+
},
45+
isItalics: true,
46+
isBold: true,
47+
},
48+
],
49+
},
50+
],
51+
};
52+
53+
const pres = automizer
54+
.loadRoot(`RootTemplate.pptx`)
55+
.load(`SlideWithTables.pptx`, 'tables');
56+
57+
const result = await pres
58+
.addSlide('tables', 3, (slide) => {
59+
slide.modifyElement('TableWithFormattedCells', [
60+
modify.setTable(data1),
61+
// modify.dump
62+
]);
63+
})
64+
.write(`modify-existing-table-format-cells.test.pptx`);
65+
66+
// Expect the first cell and the last cell to be formatted
67+
// expect(result.tables).toBe(2); // tbd
68+
});
463 Bytes
Binary file not shown.

src/classes/shape.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,12 @@ export class Shape {
200200
applyCallbacks(
201201
callbacks: ShapeModificationCallback[],
202202
element: XmlElement,
203-
arg1?: XmlElement,
203+
relation?: XmlElement,
204204
): void {
205205
callbacks.forEach((callback) => {
206206
if (typeof callback === 'function') {
207207
try {
208-
callback(element, arg1);
208+
callback(element, relation);
209209
} catch (e) {
210210
console.warn(e);
211211
}

0 commit comments

Comments
 (0)