Skip to content

Commit 6357648

Browse files
[PowerPoint] (tables) Work with text runs (#986)
* [PowerPoint] (tables) Work with text runs * Add HTML * Update based on feedback * Updates based on feedback
1 parent df2a6d2 commit 6357648

File tree

3 files changed

+180
-33
lines changed

3 files changed

+180
-33
lines changed

samples/powerpoint/shapes/add-modify-tables.yaml

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ script:
1818
document.getElementById("table-borders").addEventListener("click", () => tryCatch(tableBorders));
1919
document.getElementById("table-indent-margin").addEventListener("click", () => tryCatch(tableIndentMargin));
2020
document.getElementById("table-cell-alignment").addEventListener("click", () => tryCatch(tableCellAlignment));
21+
document.getElementById("table-text-runs").addEventListener("click", () => tryCatch(tableTextRuns));
2122
document.getElementById("table-from-shape").addEventListener("click", () => tryCatch(getTableFromShape));
2223
document.getElementById("update-table-values").addEventListener("click", () => tryCatch(updateTableValues));
2324
document.getElementById("setup").addEventListener("click", () => tryCatch(setup));
@@ -52,7 +53,7 @@ script:
5253
await PowerPoint.run(async (context) => {
5354
const shapes = context.presentation.getSelectedSlides().getItemAt(0).shapes;
5455
55-
// Add a table, specifying column widths and row heights
56+
// Add a table, specifying column widths and row heights.
5657
shapes.addTable(3, 4, {
5758
columns: [{ columnWidth: 100 }, { columnWidth: 200 }, { columnWidth: 100 }, { columnWidth: 200 }],
5859
rows: [{ rowHeight: 60 }, { rowHeight: 120 }, { rowHeight: 180 }]
@@ -101,7 +102,7 @@ script:
101102
await PowerPoint.run(async (context) => {
102103
const shapes = context.presentation.getSelectedSlides().getItemAt(0).shapes;
103104
104-
// Add a table, specifying font formatting and fill colors
105+
// Add a table, specifying font formatting and fill colors.
105106
shapes.addTable(3, 4, {
106107
values: [
107108
["A", "BB", "CCC", "DDDD"],
@@ -138,7 +139,7 @@ script:
138139
await PowerPoint.run(async (context) => {
139140
const shapes = context.presentation.getSelectedSlides().getItemAt(0).shapes;
140141
141-
// Add a table, specifying border styles
142+
// Add a table, specifying border styles.
142143
shapes.addTable(3, 4, {
143144
values: [
144145
["A", "BB", "CCC", "DDDD"],
@@ -201,6 +202,51 @@ script:
201202
});
202203
}
203204
205+
async function tableTextRuns() {
206+
// Specifies the text runs of the cells in a table.
207+
await PowerPoint.run(async (context) => {
208+
const shapes = context.presentation.getSelectedSlides().getItemAt(0).shapes;
209+
210+
// Add a table, specifying text runs.
211+
shapes.addTable(3, 4, {
212+
specificCellProperties: [
213+
[
214+
{ text: "Title text", font: { bold: true } },
215+
{ text: "Title text", font: { bold: true } },
216+
{ text: "Title text", font: { bold: true } },
217+
{ text: "Title text", font: { bold: true } }
218+
],
219+
[
220+
{ text: "Bold text", font: { bold: true } },
221+
{
222+
textRuns: [
223+
{ text: "Text runs with " },
224+
{ text: "Underlined text", font: { underline: PowerPoint.ShapeFontUnderlineStyle.double } },
225+
{ text: " and plain text" }
226+
]
227+
},
228+
{ text: "Italicized text", font: { italic: true } },
229+
{ text: "Plain text" }
230+
],
231+
[
232+
{ text: "Bold text", font: { bold: true } },
233+
{ text: "Underlined text", font: { underline: PowerPoint.ShapeFontUnderlineStyle.dotted } },
234+
{
235+
font: { bold: true },
236+
textRuns: [
237+
{ text: "Text runs with " },
238+
{ text: "italicized text", font: { italic: true } },
239+
{ text: " and (inherited) bold text" }
240+
]
241+
},
242+
{ text: "Italicized text", font: { italic: true } }
243+
]
244+
]
245+
});
246+
await context.sync();
247+
});
248+
}
249+
204250
async function getTableFromShape() {
205251
// Gets the table from a shape.
206252
await PowerPoint.run(async (context) => {
@@ -336,6 +382,9 @@ template:
336382
<button id="table-cell-alignment" class="ms-Button">
337383
<span class="ms-Button-label">Set horizontal and vertical alignments</span>
338384
</button>
385+
<button id="table-text-runs" class="ms-Button">
386+
<span class="ms-Button-label">Set text runs</span>
387+
</button>
339388
<button id="table-from-shape" class="ms-Button">
340389
<span class="ms-Button-label">Get selected table and log to console</span>
341390
</button>
65 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)