OfficeDev / script-lab

Create, run and share your code directly from Office
MIT License
706 stars 162 forks source link

Cannot swap images in PowerPoint Online properly (MSFT - report from premier customer) #1010

Closed BruceEx closed 1 year ago

BruceEx commented 1 year ago

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);

// Get itemA properties
const { top: itemATop, left: itemALeft, width: itemAWidth, height: itemAHeight } = shape1;
const { top: itemBTop, left: itemBLeft, width: itemBWidth, height: itemBHeight } = shape2;

// Swap size
shape1.top = itemBTop;
shape1.left = itemBLeft;
shape1.width = itemBWidth;
shape1.height = itemBHeight;

shape2.top = itemATop;
shape2.left = itemALeft;
shape2.width = itemAWidth;
shape2.height = itemAHeight;

return context.sync();

}); }

/* 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:

image

After we run the code, the display is wrong and conflict between slide preview (preview is correct) and slide:

image

Directly contact me tinga@microsoft.com if you have any question.

BruceEx commented 1 year ago

no one check???

ElizabethSamuel-MSFT commented 1 year ago

Looks like this is being tracked by the office-js issue so closing.