We use below code to swap size & location of pictures in the slide:
$("#run").click(() => tryCatch(run));
function run() {
// This function gets the collection of shapes on the first slide,
// and adds a text box to the collection, while specifying its text,
// location, and size. Then it names the text box.
return PowerPoint.run(async (context) => {
context.presentation.load("slides");
await context.sync();
const slide1 = context.presentation.slides.getItemAt(0);
slide1.load("shapes");
await context.sync();
const shapes = slide1.shapes;
const shape1 = shapes.getItemAt(0);
const shape2 = shapes.getItemAt(1);
shape1.load("top,left,width,height");
shape2.load("top,left,width,height");
await context.sync();
const [itemA, itemB] = shapes.items.map((item) => item.name);
/* Default helper for invoking an action and handling errors. /
async function tryCatch(callback) {
try {
await callback();
} catch (error) {
// Note: In a production add-in, you'd want to notify the user through your add-in's UI.
console.error(error);
}
}
However, it doesn't work properly in PowerPoint Online. In PowerPoint desktop (M365) it is working fine.
In PPT online, before we run the code, we have images as below:
After we run the code, the display is wrong and conflict between slide preview (preview is correct) and slide:
Environment
PowerPoint Online 16.0.16614.40524 (Microsoft 365) Edge Version 114.0.1823.43 (Official build) (64-bit)
Issue
We use below code to swap size & location of pictures in the slide:
$("#run").click(() => tryCatch(run));
function run() { // This function gets the collection of shapes on the first slide, // and adds a text box to the collection, while specifying its text, // location, and size. Then it names the text box. return PowerPoint.run(async (context) => { context.presentation.load("slides"); await context.sync(); const slide1 = context.presentation.slides.getItemAt(0); slide1.load("shapes"); await context.sync(); const shapes = slide1.shapes; const shape1 = shapes.getItemAt(0); const shape2 = shapes.getItemAt(1); shape1.load("top,left,width,height"); shape2.load("top,left,width,height"); await context.sync(); const [itemA, itemB] = shapes.items.map((item) => item.name);
}); }
/* Default helper for invoking an action and handling errors. / async function tryCatch(callback) { try { await callback(); } catch (error) { // Note: In a production add-in, you'd want to notify the user through your add-in's UI. console.error(error); } }
However, it doesn't work properly in PowerPoint Online. In PowerPoint desktop (M365) it is working fine.
In PPT online, before we run the code, we have images as below:
After we run the code, the display is wrong and conflict between slide preview (preview is correct) and slide:
Directly contact me tinga@microsoft.com if you have any question.