KSPowerPoint Reference
KSPowerPoint is the class to extend when your LWC component needs to read or write content in Microsoft PowerPoint. All methods are async and return when the PowerPoint operation completes.
Requirements:
- Keelstone Pro plan
- Keelstone PowerPoint Add-in open and connected in Microsoft PowerPoint
Import
import { KSPowerPoint } from 'kstone/api';
Slides
ksGetSlideCount()
Returns the total number of slides in the active presentation.
async ksGetSlideCount() → Promise<{ count: number }>
ksAddSlide()
Appends a new blank slide to the end of the presentation.
async ksAddSlide() → Promise<object>
ksDeleteSlide(slideIndex)
Deletes the slide at the specified index.
async ksDeleteSlide(slideIndex) → Promise<object>
| Param | Type | Description |
|---|---|---|
slideIndex | number | Zero-based slide index |
ksGetSlideText(slideIndex?)
Returns all text content from a slide, concatenated.
async ksGetSlideText(slideIndex = 0) → Promise<string>
ksExportSlide(slideIndex)
Exports a slide as a base64-encoded image.
async ksExportSlide(slideIndex) → Promise<{ base64: string }>
ksGetSlideImage(slideIndex, options?)
Returns a slide as a base64-encoded image with optional resolution and format settings.
async ksGetSlideImage(slideIndex, options = {}) → Promise<{ base64: string }>
| Param | Type | Description |
|---|---|---|
slideIndex | number | Zero-based slide index |
options.format | string | Image format (default 'png') |
options.width | number | Output width in pixels |
options.height | number | Output height in pixels |
ksInsertSlides(base64, sourceSlideIds?)
Inserts slides from a base64-encoded .pptx file into the active presentation.
async ksInsertSlides(base64, sourceSlideIds = []) → Promise<object>
| Param | Type | Default | Description |
|---|---|---|---|
base64 | string | required | Base64-encoded .pptx file |
sourceSlideIds | string[] | [] | Specific slide IDs to insert. Empty array inserts all slides. |
Shapes
ksGetShapes(slideIndex?)
Returns all shapes on a slide.
async ksGetShapes(slideIndex = 0) → Promise<{ name: string, type: string, text?: string }[]>
const shapes = await this.ksGetShapes(0);
// [{ name: 'Title 1', type: 'placeholder', text: 'Slide title' }, ...]
ksAddTextBox(slideIndex, text, options?)
Adds a text box to a slide.
async ksAddTextBox(slideIndex, text, options = {}) → Promise<object>
| Param | Type | Description |
|---|---|---|
slideIndex | number | Zero-based slide index |
text | string | Text content |
options.left | number | Left position in points |
options.top | number | Top position in points |
options.width | number | Width in points |
options.height | number | Height in points |
options.fontSize | number | Font size in points |
options.bold | boolean | Bold text |
options.color | string | Font colour as hex, e.g. '#032D60' |
ksAddImage(slideIndex, base64, options?)
Adds an image to a slide.
async ksAddImage(slideIndex, base64, options = {}) → Promise<object>
| Param | Type | Description |
|---|---|---|
slideIndex | number | Zero-based slide index |
base64 | string | Base64-encoded image (PNG, JPG, etc.) |
options.left | number | Left position in points |
options.top | number | Top position in points |
options.width | number | Width in points |
options.height | number | Height in points |
ksSetShapeText(slideIndex, shapeName, text)
Replaces the text content of a named shape on a slide.
async ksSetShapeText(slideIndex, shapeName, text) → Promise<object>
| Param | Type | Description |
|---|---|---|
slideIndex | number | Zero-based slide index |
shapeName | string | Name of the shape as shown in the Selection Pane |
text | string | New text content |
const shapes = await this.ksGetShapes(0);
const title = shapes.find(s => s.name === 'Title 1');
if (title) await this.ksSetShapeText(0, title.name, 'Updated Title');
ksDeleteShape(slideIndex, shapeName)
Deletes a named shape from a slide.
async ksDeleteShape(slideIndex, shapeName) → Promise<object>
Slide tags
Slide tags are key/value strings stored in the presentation XML. They are not visible to end users and are useful for tracking metadata such as Salesforce record IDs or template versions.
ksAddTag(slideIndex, key, value)
Sets a tag on a slide.
async ksAddTag(slideIndex, key, value) → Promise<object>
ksGetTags(slideIndex)
Returns all tags on a slide.
async ksGetTags(slideIndex) → Promise<{ [key: string]: string }>
Presentation generation
ksGeneratePresentation(slides, options?)
Generates a fully formatted PowerPoint presentation server-side and inserts it into the open file.
async ksGeneratePresentation(slides, options = {}) → Promise<{ base64: string }>
| Param | Type | Description |
|---|---|---|
slides | object[] | Array of slide definition objects — see POST /api/powerpoint/generate |
options.footer | string | Footer text shown on every slide |
options.theme | object | Colour overrides — see API reference |
await this.ksGeneratePresentation(
[
{ type: 'cover', title: 'Acme Corp — Q3 Review', subtitle: 'Sales Operations' },
{ type: 'bullets', title: 'Pipeline', bullets: ['$2.1M open', '14 active deals'] },
],
{ footer: 'Confidential' }
);
See POST /api/powerpoint/generate for the full slide type reference.
Notes
ksGetNotes(slideIndex?)
Returns the speaker notes text for a slide.
async ksGetNotes(slideIndex = 0) → Promise<{ notes: string }>
Requires PowerPoint API set 1.5 or later.
ksSetNotes(notes, slideIndex?)
Sets the speaker notes for a slide. Replaces existing notes.
async ksSetNotes(notes, slideIndex = 0) → Promise<{ ok: true }>
Requires PowerPoint API set 1.5 or later.
Slide background
ksSetSlideBackground(color, slideIndex?)
Sets a solid colour background on a slide by inserting a full-slide rectangle named ks-background behind all other shapes. Calling this again replaces the previous background.
async ksSetSlideBackground(color, slideIndex = 0) → Promise<{ ok: true }>
| Param | Type | Description |
|---|---|---|
color | string | CSS hex colour, e.g. '#032D60' |
slideIndex | number | Zero-based slide index |
await this.ksSetSlideBackground('#032D60'); // Salesforce dark navy
This method adds a shape rather than modifying the slide theme. If you need theme-level background changes, modify the PPTX XML directly using ksGetFile().
Shape formatting & positioning
ksFormatShape(slideIndex, shapeIdentifier, format)
Applies fill, border, and text formatting to a shape identified by name or index.
async ksFormatShape(slideIndex, shapeIdentifier, format) → Promise<{ ok: true }>
| Param | Type | Description |
|---|---|---|
slideIndex | number | Zero-based slide index |
shapeIdentifier | string | number | Shape name (string) or index (number) |
format.fillColor | string | Fill colour hex |
format.lineColor | string | Border colour hex |
format.lineWeight | number | Border weight in points |
format.lineVisible | boolean | Show or hide the border |
format.fontColor | string | Text font colour hex |
format.fontSize | number | Text font size in points |
format.bold | boolean | Bold text |
format.italic | boolean | Italic text |
await this.ksFormatShape(0, 'Title 1', { bold: true, fontColor: '#FFFFFF', fillColor: '#032D60' });
ksResizeShape(slideIndex, shapeIdentifier, options)
Repositions or resizes a shape on a slide.
async ksResizeShape(slideIndex, shapeIdentifier, options) → Promise<{ ok: true }>
options field | Type | Description |
|---|---|---|
left | number | Left edge in points |
top | number | Top edge in points |
width | number | Width in points |
height | number | Height in points |
All fields are optional — only provided values are updated.
ksGetSelection()
Returns the shapes currently selected in the presentation.
async ksGetSelection() → Promise<{ selection: { id: string, name: string, type: string, left: number, top: number, width: number, height: number }[] }>
Requires PowerPoint API set 1.5 or later.
Tables
ksAddTable(slideIndex, rows, columns, options?)
Adds a table shape to a slide.
async ksAddTable(slideIndex, rows, columns, options = {}) → Promise<{ ok: true }>
| Param | Type | Default | Description |
|---|---|---|---|
slideIndex | number | 0 | Zero-based slide index |
rows | number | — | Number of rows |
columns | number | — | Number of columns |
options.left | number | 72 | Left position in points |
options.top | number | 72 | Top position in points |
options.width | number | 400 | Width in points |
options.height | number | 200 | Height in points |
options.values | any[][] | — | 2D array to pre-populate table cells |
await this.ksAddTable(0, 3, 4, {
left: 72, top: 144, width: 576, height: 200,
values: [
['Region', 'Q1', 'Q2', 'Q3'],
['AMER', '$1M', '$1.2M', '$1.4M'],
['EMEA', '$0.8M', '$0.9M', '$1M'],
]
});
Slide reordering
ksDuplicateSlide(slideIndex?)
Duplicates a slide and inserts the copy immediately after the original.
async ksDuplicateSlide(slideIndex?) → Promise<{ ok: true }>
Requires PowerPoint API set 1.5 or later.
ksMoveSlide(fromIndex, toIndex)
Moves a slide to a new position. Other slides shift accordingly.
async ksMoveSlide(fromIndex, toIndex) → Promise<{ ok: true }>
Requires PowerPoint API set 1.5 or later.
ksCall(endpoint, body?)
Low-level method inherited from DocumentAPI. Call this when you need to reach a server endpoint not covered by a named method.
async ksCall(endpoint, body = {}) → Promise<any>
Minimal example
import { KSPowerPoint } from 'kstone/api';
import { api, track } from 'lwc';
import getOpportunityData from '@salesforce/apex/OpportunityController.getData';
export default class SalesDeckBuilder extends KSPowerPoint {
@api keelstoneSessionId;
@api recordId;
@track status = '';
async handleGenerate() {
try {
const data = await getOpportunityData({ opportunityId: this.recordId });
await this.ksGeneratePresentation(
[
{ type: 'cover', title: data.name, subtitle: data.accountName },
{ type: 'bullets', title: 'Overview', bullets: [
`Stage: ${data.stageName}`,
`Amount: $${data.amount}`,
`Close Date: ${data.closeDate}`,
]},
],
{ footer: `Prepared ${new Date().toLocaleDateString()}` }
);
this.status = 'Deck inserted into PowerPoint.';
} catch (err) {
this.status = `Error: ${err.message}`;
}
}
}
Flow Wiring
Wire KeelstoneSessionId from the flow to your component's keelstoneSessionId property. See Flow Wiring.