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
auto |
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. |
bottom |
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. |
has |
Specifies if the text frame contains text. |
left |
Represents the left margin, in points, of the text frame. |
right |
Represents the right margin, in points, of the text frame. |
text |
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. |
top |
Represents the top margin, in points, of the text frame. |
vertical |
Represents the vertical alignment of the text frame. See PowerPoint.TextVerticalAlignment for details. |
word |
Determines whether lines break automatically to fit text inside the shape. |
Methods
delete |
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 |
load(property |
Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
toJSON() | Overrides the JavaScript |
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
bottomMargin
Represents the bottom margin, in points, of the text frame.
bottomMargin: number;
Property Value
number
Remarks
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
leftMargin
Represents the left margin, in points, of the text frame.
leftMargin: number;
Property Value
number
Remarks
rightMargin
Represents the right margin, in points, of the text frame.
rightMargin: number;
Property Value
number
Remarks
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
topMargin
Represents the top margin, in points, of the text frame.
topMargin: number;
Property Value
number
Remarks
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
wordWrap
Determines whether lines break automatically to fit text inside the shape.
wordWrap: boolean;
Property Value
boolean
Remarks
Method Details
deleteText()
Deletes all the text in the text frame.
deleteText(): void;
Returns
void
Remarks
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
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
Office Add-ins