Here’s a description you can use for your Stack Overflow post:
Description:
I’m working on a PowerPoint add-in using Office.js and need to flip or rotate grouped shapes horizontally. However, I’m encountering some issues:
- Flip Functionality: I tried using
shape.flip("Horizontal")
, but it doesn’t seem to work for grouped shapes. - Rotation Property: When attempting to access or set the rotation property, I get
undefined
orNaN
.
Here’s a simplified version of the code I’m working with:
PowerPoint.run(async (context) => {
const slide = context.presentation.slides.getActiveSlide();
const selectedShapes = slide.shapes.getSelected();
selectedShapes.load("id,name,type,width,height,left,top");
await context.sync();
selectedShapes.items.forEach(shape => {
console.log(`Shape Details Before Rotation:`);
console.log(`ID: ${shape.id}`);
console.log(`Name: ${shape.name}`);
console.log(`Type: ${shape.type}`);
console.log(`Width: ${shape.width}`);
console.log(`Height: ${shape.height}`);
console.log(`Left: ${shape.left}`);
console.log(`Top: ${shape.top}`);
console.log(`Rotation: ${shape.rotation}`);
// Attempting to rotate
shape.rotation = shape.rotation + 180;
console.log(`Shape Details After Rotation:`);
console.log(`ID: ${shape.id}`);
console.log(`Name: ${shape.name}`);
console.log(`Type: ${shape.type}`);
console.log(`Width: ${shape.width}`);
console.log(`Height: ${shape.height}`);
console.log(`Left: ${shape.left}`);
console.log(`Top: ${shape.top}`);
console.log(`Rotation: ${shape.rotation}`);
});
await context.sync();
});
Issues:
- The
shape.flip("Horizontal")
method does not seem to apply to grouped shapes. - The
shape.rotation
property is returningundefined
orNaN
.
Environment:
- PowerPoint Add-in using Office.js
- Office.js API Version: [insert version]
Questions:
- How can I correctly flip or rotate grouped shapes in PowerPoint using Office.js?
- Is there a workaround or alternative approach to achieve this?
Any insights or suggestions would be greatly appreciated!
What I Tried:
-
Flipping Shapes:
- I attempted to use the
shape.flip("Horizontal")
method to flip selected shapes horizontally. This worked for individual shapes, but when applied to grouped shapes, it had no effect.
- I attempted to use the
-
Rotating Shapes:
- I tried accessing and setting the
shape.rotation
property to rotate the shapes by 180 degrees. However, theshape.rotation
property returnedundefined
before rotation andNaN
after attempting to set it, indicating that rotation might not be supported or available for grouped shapes.
- I tried accessing and setting the
-
Logging Shape Properties:
- I logged various properties of the selected shapes (ID, name, type, width, height, left, top, and rotation) before and after attempting the flip and rotation. This helped me verify that the flip and rotation were not being applied as expected.
What I Was Expecting:
-
Successful Flip:
- I expected the
shape.flip("Horizontal")
method to flip all selected shapes horizontally, including grouped shapes, as it does for individual shapes.
- I expected the
-
Rotation Support:
- I expected to access the current rotation value of the shape, modify it, and then apply the new rotation to the shape, including for grouped shapes.
-
Accurate Property Logging:
- I expected the rotation property to reflect the correct rotation value before and after applying the transformation, rather than returning
undefined
orNaN
.
- I expected the rotation property to reflect the correct rotation value before and after applying the transformation, rather than returning
My goal was to successfully flip or rotate grouped shapes in PowerPoint using Office.js, but I’m facing challenges in achieving this.
Mohammed Alostah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.