Excel.TextFrame class
Represents the text frame of a shape object.
- Extends
Remarks
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. |
| horizontal |
Represents the horizontal alignment of the text frame. See |
| horizontal |
Represents the horizontal overflow behavior of the text frame. See |
| left |
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 |
| reading |
Represents the reading order of the text frame, either left-to-right or right-to-left. See |
| 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 |
| top |
Represents the top margin, in points, of the text frame. |
| vertical |
Represents the vertical alignment of the text frame. See |
| vertical |
Represents the vertical overflow behavior of the text frame. See |
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 |
| 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 |
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
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
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
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
leftMargin
Represents the left margin, in points, of the text frame.
leftMargin: number;
Property Value
number
Remarks
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
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
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 Excel.TextRange for details.
readonly textRange: Excel.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 Excel.ShapeTextVerticalAlignment for details.
verticalAlignment: Excel.ShapeTextVerticalAlignment | "Top" | "Middle" | "Bottom" | "Justified" | "Distributed";
Property Value
Excel.ShapeTextVerticalAlignment | "Top" | "Middle" | "Bottom" | "Justified" | "Distributed"
Remarks
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
Method Details
deleteText()
Deletes all the text in the text frame.
deleteText(): void;
Returns
void
Remarks
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
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's 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;