Excel.TextFrame class

Represents the text frame of a shape object.

Extends

Remarks

[ API set: ExcelApi 1.9 ]

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.

horizontalAlignment

Represents the horizontal alignment of the text frame. See Excel.ShapeTextHorizontalAlignment for details.

horizontalOverflow

Represents the horizontal overflow behavior of the text frame. See Excel.ShapeTextHorizontalOverflow for details.

leftMargin

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

orientation

Represents the angle to which the text is oriented for the text frame. See Excel.ShapeTextOrientation for details.

readingOrder

Represents the reading order of the text frame, either left-to-right or right-to-left. See Excel.ShapeTextReadingOrder for details.

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 Excel.TextRange for details.

topMargin

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

verticalAlignment

Represents the vertical alignment of the text frame. See Excel.ShapeTextVerticalAlignment for details.

verticalOverflow

Represents the vertical overflow behavior of the text frame. See Excel.ShapeTextVerticalOverflow for details.

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.

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

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 Excel.TextFrame object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.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: Excel.ShapeAutoSize | "AutoSizeNone" | "AutoSizeTextToFitShape" | "AutoSizeShapeToFitText" | "AutoSizeMixed";

Property Value

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

Remarks

[ API set: ExcelApi 1.9 ]

bottomMargin

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

bottomMargin: number;

Property Value

number

Remarks

[ API set: ExcelApi 1.9 ]

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: ExcelApi 1.9 ]

horizontalAlignment

Represents the horizontal alignment of the text frame. See Excel.ShapeTextHorizontalAlignment for details.

horizontalAlignment: Excel.ShapeTextHorizontalAlignment | "Left" | "Center" | "Right" | "Justify" | "JustifyLow" | "Distributed" | "ThaiDistributed";

Property Value

Excel.ShapeTextHorizontalAlignment | "Left" | "Center" | "Right" | "Justify" | "JustifyLow" | "Distributed" | "ThaiDistributed"

Remarks

[ API set: ExcelApi 1.9 ]

horizontalOverflow

Represents the horizontal overflow behavior of the text frame. See Excel.ShapeTextHorizontalOverflow for details.

horizontalOverflow: Excel.ShapeTextHorizontalOverflow | "Overflow" | "Clip";

Property Value

Excel.ShapeTextHorizontalOverflow | "Overflow" | "Clip"

Remarks

[ API set: ExcelApi 1.9 ]

leftMargin

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

leftMargin: number;

Property Value

number

Remarks

[ API set: ExcelApi 1.9 ]

orientation

Represents the angle to which the text is oriented for the text frame. See Excel.ShapeTextOrientation for details.

orientation: Excel.ShapeTextOrientation | "Horizontal" | "Vertical" | "Vertical270" | "WordArtVertical" | "EastAsianVertical" | "MongolianVertical" | "WordArtVerticalRTL";

Property Value

Excel.ShapeTextOrientation | "Horizontal" | "Vertical" | "Vertical270" | "WordArtVertical" | "EastAsianVertical" | "MongolianVertical" | "WordArtVerticalRTL"

Remarks

[ API set: ExcelApi 1.9 ]

readingOrder

Represents the reading order of the text frame, either left-to-right or right-to-left. See Excel.ShapeTextReadingOrder for details.

readingOrder: Excel.ShapeTextReadingOrder | "LeftToRight" | "RightToLeft";

Property Value

Excel.ShapeTextReadingOrder | "LeftToRight" | "RightToLeft"

Remarks

[ API set: ExcelApi 1.9 ]

rightMargin

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

rightMargin: number;

Property Value

number

Remarks

[ API set: ExcelApi 1.9 ]

textRange

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

readonly textRange: Excel.TextRange;

Property Value

Remarks

[ API set: ExcelApi 1.9 ]

topMargin

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

topMargin: number;

Property Value

number

Remarks

[ API set: ExcelApi 1.9 ]

verticalAlignment

Represents the vertical alignment of the text frame. See Excel.ShapeTextVerticalAlignment for details.

verticalAlignment: Excel.ShapeTextVerticalAlignment | "Top" | "Middle" | "Bottom" | "Justified" | "Distributed";

Property Value

Excel.ShapeTextVerticalAlignment | "Top" | "Middle" | "Bottom" | "Justified" | "Distributed"

Remarks

[ API set: ExcelApi 1.9 ]

verticalOverflow

Represents the vertical overflow behavior of the text frame. See Excel.ShapeTextVerticalOverflow for details.

verticalOverflow: Excel.ShapeTextVerticalOverflow | "Overflow" | "Ellipsis" | "Clip";

Property Value

Excel.ShapeTextVerticalOverflow | "Overflow" | "Ellipsis" | "Clip"

Remarks

[ API set: ExcelApi 1.9 ]

Method Details

deleteText()

Deletes all the text in the text frame.

deleteText(): void;

Returns

void

Remarks

[ API set: ExcelApi 1.9 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/44-shape/shape-textboxes.yaml

await Excel.run(async (context) => {
    const shapes = context.workbook.worksheets.getItem("Shapes").shapes;
    const textbox = shapes.getItem("Textbox");
    textbox.textFrame.deleteText();
    await context.sync();
});

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?: Excel.Interfaces.TextFrameLoadOptions): Excel.TextFrame;

Parameters

options
Excel.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[]): Excel.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;
        }): Excel.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

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties: Interfaces.TextFrameUpdateData, options?: OfficeExtension.UpdateOptions): void;

Parameters

properties
Excel.Interfaces.TextFrameUpdateData

A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.

options
OfficeExtension.UpdateOptions

Provides an option to suppress errors if the properties object tries to set any read-only properties.

Returns

void

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

set(properties: Excel.TextFrame): void;

Parameters

properties
Excel.TextFrame

Returns

void

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 Excel.TextFrame object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.TextFrameData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.TextFrameData;

Returns