A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
Message from office-js bot:
We’re closing this issue because it has been inactive for a long time. We’re doing this to keep the issues list manageable and useful for everyone. If this issue is still relevant for you, please create a new issue.
Thank you for your understanding and continued feedback.
Created a task pane PowerPoint Add-in which creates a new slide and add some text and images on it. The add-in is working as expected in PowerPoint desktop, but fails to render the same content when executed on PowerPoint Online. The add-in is a task pane project using react and TypeScript. The code used to create the slide and add the content is:
return PowerPoint.run(async (context) => {
try {
const presentation = context.presentation;
// Add new slide
presentation.slides.add();
await context.sync();
// If we wait a couple seconds here we avoid an error in PowerPoint Online
// await sleep(2000);
// Get the number of slides in presentation
const slideCount = presentation.slides.getCount();
await context.sync();
// Get a reference to the last slide
const slide = presentation.slides.getItemAt(slideCount.value - 1);
slide.shapes.load("items/$none");
await context.sync();
// Delete all shapes in the slide
slide.shapes.items.forEach((shape) => {
shape.delete();
});
await context.sync();
// Add title to slide
const titleOptions: PowerPoint.ShapeAddOptions = {
top: 25,
left: 25,
height: 50,
width: 915,
};
const title = slide.shapes.addTextBox("Lorem ipsum dolor sit amet", titleOptions);
title.textFrame.textRange.font.name = "Calibri Light";
title.textFrame.textRange.font.size = 28;
title.textFrame.autoSizeSetting = PowerPoint.ShapeAutoSize.autoSizeTextToFitShape;
// Add description to slide
const descriptionOptions: PowerPoint.ShapeAddOptions = {
top: 80,
left: 330,
height: 415,
width: 610,
};
const description = slide.shapes.addTextBox("Nam tristique ... tempor vestibulum.", descriptionOptions);
description.textFrame.textRange.font.name = "Calibri Light";
description.textFrame.textRange.font.size = 16;
description.textFrame.autoSizeSetting = PowerPoint.ShapeAutoSize.autoSizeTextToFitShape;
// Go to the last slide
Office.context.document.goToByIdAsync(Office.Index.Last, Office.GoToType.Slide, async () => {
const pictureOptions = {
coercionType: Office.CoercionType.Image,
imageTop: 80,
imageLeft: 25,
imageWidth: 300,
};
// Add a picture in the selected slide
Office.context.document.setSelectedDataAsync(
"PD94bWwgdm ... 3ZnPgo=",
pictureOptions
);
});
} catch (error) {
console.error(error);
}
});
Your Environment
Platform [PC desktop, Mac, iOS, Office on the web]:
PC desktop
Mac
Office on the web
Host [Excel, Word, PowerPoint, etc.]: PowerPoint
Office version number:
On Windows, Microsoft PowerPoint for Microsoft 365 MSO (Version 2209 Build 16.0.15629.20200) 64-bit
On macOS, Microsoft PowerPoint for Mac Microsoft 365 (Version 16.67 22101200)
Operating System:
macOS Monterrey v12.6
Windows 11 Pro 21H2
Browser (if using Office on the web):
On macOS, Microsoft Edge Chromium v106.0.1370.42 (macOS)
On Windows, Microsoft Edge Chromium v106.0.1370.47 (Windows 11)
Expected behavior
When the add- in is executed in PowerPoint desktop, the slide is created, the content is added to the new slide, and the slide is selected:
Current behavior
When the add-in is executed in PowerPoint Online, the slide is created, no text is added, and the image is added to the first slide:
Also, the following error is captured in the console:
RichApi.Error: InvalidParam passed to GetItem(id)
at new n (powerpoint-web-16.00.js:26:304803)
at r.processRequestExecutorResponseMessage (powerpoint-web-16.00.js:26:369137)
at powerpoint-web-16.00.js:26:367199
If a wait is performed right after the slide creation the text is correctly rendered, but the image is still being added to the first slide:
Created a task pane PowerPoint Add-in which creates a new slide and add some text and images on it. The add-in is working as expected in PowerPoint desktop, but fails to render the same content when executed on PowerPoint Online. The add-in is a task pane project using react and TypeScript. The code used to create the slide and add the content is:
Your Environment
Expected behavior
When the add- in is executed in PowerPoint desktop, the slide is created, the content is added to the new slide, and the slide is selected:
Current behavior
When the add-in is executed in PowerPoint Online, the slide is created, no text is added, and the image is added to the first slide:
Also, the following error is captured in the console:
If a wait is performed right after the slide creation the text is correctly rendered, but the image is still being added to the first slide:
Steps to reproduce
npm run dev-server
npm run start:web -- --document <URL of a PowerPoint document in OneDrive>
Link to live example(s)
An example is available at emiliodangelo/powerpoint-addin-example repo.