Here’s a sample OfficeScript that demonstrates how to create a PowerPoint presentation, add shapes, and add text to the slides:
function createPowerPoint() { // Create a PowerPoint presentation var presentation = context.presentation.create(); // Add a slide to the presentation var slide = presentation.slides.add(); // Add a rectangle shape to the slide var rectangle = slide.shapes.addShape("Rectangle", 100, 100, 200, 100); // Add text to the rectangle shape var textFrame = rectangle.textFrame; textFrame.textRange.text = "Hello, PowerPoint!"; // Save the presentation presentation.save("SamplePresentation.pptx"); }
In this example, the createPowerPoint
function performs the following steps:
It creates a new PowerPoint presentation using the
context.presentation.create()
method.It adds a slide to the presentation using the
slides.add()
method.It adds a rectangle shape to the slide using the
shapes.addShape()
method. The parameters specify the position and dimensions of the rectangle.It accesses the text frame of the rectangle shape using the
textFrame
property.It sets the text of the rectangle shape using the
textRange.text
property.Finally, it saves the presentation with the specified file name using the
presentation.save()
method.
You can call the createPowerPoint
function to create the PowerPoint presentation with a rectangle shape and text. The presentation will be saved with the name “SamplePresentation.pptx”.
Please note that OfficeScripts for PowerPoint are currently only supported in PowerPoint for the web, and you need to have the appropriate permissions to create and save presentations.