PowerPoint.TextFrame class

Represents the text frame of a shape object.

Extends

Remarks

[ API set: PowerPointApi 1.4 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/text/get-set-textrange.yaml

// Selects the first 10 characters of the selected shape.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  await context.sync();
  if (shapeCount.value !== 1) {
    console.warn("You must select only one shape with text in it.");
    return;
  }
  const shape: PowerPoint.Shape = shapes.getItemAt(0);
  const textFrame: PowerPoint.TextFrame = shape.textFrame.load("textRange,hasText");
  await context.sync();
  if (textFrame.hasText != true) {
    console.warn("You must select only one shape with text in it.");
    return;
  }
  const textRange: PowerPoint.TextRange = textFrame.textRange;
  textRange.load("text");
  await context.sync();
  if (textRange.text.length < 10) {
    console.warn("You must select only one shape with at least 10 characters in it.");
    return;
  }
  const textRange10 = textRange.getSubstring(0, 10);
  textRange10.setSelected();
  await context.sync();
});

Properties

autoSizeSetting

The automatic sizing settings for the text frame. A text frame can be set to automatically fit the text to the text frame, to automatically fit the text frame to the text, or not perform any automatic sizing.

bottomMargin

Represents the bottom margin, in points, of the text frame.

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

hasText

Specifies if the text frame contains text.

leftMargin

Represents the left margin, in points, of the text frame.

rightMargin

Represents the right margin, in points, of the text frame.

textRange

Represents the text that is attached to a shape in the text frame, and properties and methods for manipulating the text. See PowerPoint.TextRange for details.

topMargin

Represents the top margin, in points, of the text frame.

verticalAlignment

Represents the vertical alignment of the text frame. See PowerPoint.TextVerticalAlignment for details.

wordWrap

Determines whether lines break automatically to fit text inside the shape.

Methods

deleteText()

Deletes all the text in the text frame.

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original PowerPoint.TextFrame object is an API object, the toJSON method returns a plain JavaScript object (typed as PowerPoint.Interfaces.TextFrameData) that contains shallow copies of any loaded child properties from the original object.

Property Details

autoSizeSetting

The automatic sizing settings for the text frame. A text frame can be set to automatically fit the text to the text frame, to automatically fit the text frame to the text, or not perform any automatic sizing.

autoSizeSetting: PowerPoint.ShapeAutoSize | "AutoSizeNone" | "AutoSizeTextToFitShape" | "AutoSizeShapeToFitText" | "AutoSizeMixed";

Property Value

PowerPoint.ShapeAutoSize | "AutoSizeNone" | "AutoSizeTextToFitShape" | "AutoSizeShapeToFitText" | "AutoSizeMixed"

Remarks

[ API set: PowerPointApi 1.4 ]

bottomMargin

Represents the bottom margin, in points, of the text frame.

bottomMargin: number;

Property Value

number

Remarks

[ API set: PowerPointApi 1.4 ]

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

hasText

Specifies if the text frame contains text.

readonly hasText: boolean;

Property Value

boolean

Remarks

[ API set: PowerPointApi 1.4 ]

leftMargin

Represents the left margin, in points, of the text frame.

leftMargin: number;

Property Value

number

Remarks

[ API set: PowerPointApi 1.4 ]

rightMargin

Represents the right margin, in points, of the text frame.

rightMargin: number;

Property Value

number

Remarks

[ API set: PowerPointApi 1.4 ]

textRange

Represents the text that is attached to a shape in the text frame, and properties and methods for manipulating the text. See PowerPoint.TextRange for details.

readonly textRange: PowerPoint.TextRange;

Property Value

Remarks

[ API set: PowerPointApi 1.4 ]

topMargin

Represents the top margin, in points, of the text frame.

topMargin: number;

Property Value

number

Remarks

[ API set: PowerPointApi 1.4 ]

verticalAlignment

Represents the vertical alignment of the text frame. See PowerPoint.TextVerticalAlignment for details.

verticalAlignment: PowerPoint.TextVerticalAlignment | "Top" | "Middle" | "Bottom" | "TopCentered" | "MiddleCentered" | "BottomCentered";

Property Value

PowerPoint.TextVerticalAlignment | "Top" | "Middle" | "Bottom" | "TopCentered" | "MiddleCentered" | "BottomCentered"

Remarks

[ API set: PowerPointApi 1.4 ]

wordWrap

Determines whether lines break automatically to fit text inside the shape.

wordWrap: boolean;

Property Value

boolean

Remarks

[ API set: PowerPointApi 1.4 ]

Method Details

deleteText()

Deletes all the text in the text frame.

deleteText(): void;

Returns

void

Remarks

[ API set: PowerPointApi 1.4 ]

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(options?: PowerPoint.Interfaces.TextFrameLoadOptions): PowerPoint.TextFrame;

Parameters

options
PowerPoint.Interfaces.TextFrameLoadOptions

Provides options for which properties of the object to load.

Returns

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): PowerPoint.TextFrame;

Parameters

propertyNames

string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): PowerPoint.TextFrame;

Parameters

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original PowerPoint.TextFrame object is an API object, the toJSON method returns a plain JavaScript object (typed as PowerPoint.Interfaces.TextFrameData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): PowerPoint.Interfaces.TextFrameData;

Returns