OfficeScripts to create a PowerPoint and add Shapes and Text to it

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:

  1. It creates a new PowerPoint presentation using the context.presentation.create() method.

  2. It adds a slide to the presentation using the slides.add() method.

  3. It adds a rectangle shape to the slide using the shapes.addShape() method. The parameters specify the position and dimensions of the rectangle.

  4. It accesses the text frame of the rectangle shape using the textFrame property.

  5. It sets the text of the rectangle shape using the textRange.text property.

  6. 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.

Pamai Tech
Turning ideas into Reality

Products

Office Add-in

Enterprise Solutions

Cloud Consulting

UI UX Design

Data Transformation

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2023 Pamai Tech