Excel.TextFrame class

Represents the text frame of a shape object.

[ API set: ExcelApi 1.9 ]

Extends
OfficeExtension.ClientObject

Properties

autoSizeSetting

Gets or sets 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.

[ API set: ExcelApi 1.9 ]

bottomMargin

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

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

hasText

Specifies whether the text frame contains text.

[ API set: ExcelApi 1.9 ]

horizontalAlignment

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

[ API set: ExcelApi 1.9 ]

horizontalOverflow

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

[ API set: ExcelApi 1.9 ]

leftMargin

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

[ API set: ExcelApi 1.9 ]

orientation

Represents the text orientation of the text frame. See Excel.ShapeTextOrientation for details.

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

[ API set: ExcelApi 1.9 ]

rightMargin

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

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

[ API set: ExcelApi 1.9 ]

topMargin

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

[ API set: ExcelApi 1.9 ]

verticalAlignment

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

[ API set: ExcelApi 1.9 ]

verticalOverflow

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

[ API set: ExcelApi 1.9 ]

Methods

deleteText()

Deletes all the text in the text frame.

[ API set: ExcelApi 1.9 ]

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

Gets or sets 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.

[ API set: ExcelApi 1.9 ]

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

Property Value

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

bottomMargin

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

[ API set: ExcelApi 1.9 ]

bottomMargin: number;

Property Value

number

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 whether the text frame contains text.

[ API set: ExcelApi 1.9 ]

readonly hasText: boolean;

Property Value

boolean

horizontalAlignment

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

[ API set: ExcelApi 1.9 ]

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

Property Value

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

horizontalOverflow

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

[ API set: ExcelApi 1.9 ]

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

Property Value

Excel.ShapeTextHorizontalOverflow | "Overflow" | "Clip"

leftMargin

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

[ API set: ExcelApi 1.9 ]

leftMargin: number;

Property Value

number

orientation

Represents the text orientation of the text frame. See Excel.ShapeTextOrientation for details.

[ API set: ExcelApi 1.9 ]

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

Property Value

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

readingOrder

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

[ API set: ExcelApi 1.9 ]

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

Property Value

Excel.ShapeTextReadingOrder | "LeftToRight" | "RightToLeft"

rightMargin

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

[ API set: ExcelApi 1.9 ]

rightMargin: number;

Property Value

number

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.

[ API set: ExcelApi 1.9 ]

readonly textRange: Excel.TextRange;

Property Value

topMargin

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

[ API set: ExcelApi 1.9 ]

topMargin: number;

Property Value

number

verticalAlignment

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

[ API set: ExcelApi 1.9 ]

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

Property Value

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

verticalOverflow

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

[ API set: ExcelApi 1.9 ]

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

Property Value

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

Method Details

deleteText()

Deletes all the text in the text frame.

[ API set: ExcelApi 1.9 ]

deleteText(): void;

Returns

void

Examples

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

Remarks

This method has the following additional signature:

set(properties: Excel.TextFrame): 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