Google Apps Script API
    Preparing search index...

    An element representing a rich text region. All text in a Document is contained within Text elements. A Text element can be contained within an Equation, EquationFunction, ListItem, or Paragraph, but cannot itself contain any other element. For more information on document structure, see the guide to extending Google Docs.

    var body = DocumentApp.getActiveDocument().getBody();
    
    // Use editAsText to obtain a single text element containing
    // all the characters in the document.
    var text = body.editAsText();
    
    // Insert text at the beginning of the document.
    text.insertText(0, 'Inserted text.\n');
    
    // Insert text at the end of the document.
    text.appendText('\nAppended text.');
    
    // Make the first half of the document blue.
    text.setForegroundColor(0, text.getText().length / 2, '#00FFFF');
    
    interface Text {
        appendText(text: string): GoogleAppsScript.Document.Text;
        asBody(): GoogleAppsScript.Document.Body;
        asDate(): GoogleAppsScript.Document.Date;
        asEquation(): GoogleAppsScript.Document.Equation;
        asEquationFunction(): EquationFunction;
        asEquationFunctionArgumentSeparator(): EquationFunctionArgumentSeparator;
        asEquationSymbol(): EquationSymbol;
        asFooterSection(): FooterSection;
        asFootnote(): GoogleAppsScript.Document.Footnote;
        asFootnoteSection(): FootnoteSection;
        asHeaderSection(): HeaderSection;
        asHorizontalRule(): GoogleAppsScript.Document.HorizontalRule;
        asInlineDrawing(): InlineDrawing;
        asInlineImage(): InlineImage;
        asListItem(): GoogleAppsScript.Document.ListItem;
        asPageBreak(): GoogleAppsScript.Document.PageBreak;
        asParagraph(): GoogleAppsScript.Document.Paragraph;
        asPerson(): GoogleAppsScript.Document.Person;
        asRichLink(): RichLink;
        asTable(): GoogleAppsScript.Document.Table;
        asTableCell(): GoogleAppsScript.Document.TableCell;
        asTableOfContents(): GoogleAppsScript.Document.TableOfContents;
        asTableRow(): GoogleAppsScript.Document.TableRow;
        asText(): GoogleAppsScript.Document.Text;
        copy(): GoogleAppsScript.Document.Text;
        deleteText(
            startOffset: number,
            endOffsetInclusive: number,
        ): GoogleAppsScript.Document.Text;
        editAsText(): GoogleAppsScript.Document.Text;
        findText(searchPattern: string, from?: RangeElement): RangeElement;
        getAttributes(offset?: number): any;
        getBackgroundColor(offset?: number): string;
        getFontFamily(offset?: number): string;
        getFontSize(offset?: number): number;
        getForegroundColor(offset?: number): string;
        getLinkUrl(offset?: number): string;
        getNextSibling(): GoogleAppsScript.Document.Element;
        getParent(): ContainerElement;
        getPreviousSibling(): GoogleAppsScript.Document.Element;
        getText(): string;
        getTextAlignment(offset?: number): TextAlignment;
        getTextAttributeIndices(): number[];
        getType(): ElementType;
        insertText(offset: number, text: string): GoogleAppsScript.Document.Text;
        isAtDocumentEnd(): boolean;
        isBold(offset?: number): boolean;
        isItalic(offset?: number): boolean;
        isStrikethrough(offset?: number): boolean;
        isUnderline(offset?: number): boolean;
        merge(): GoogleAppsScript.Document.Text;
        removeFromParent(): GoogleAppsScript.Document.Text;
        replaceText(
            searchPattern: string,
            replacement: string,
        ): GoogleAppsScript.Document.Element;
        setAttributes(
            startOffset: number,
            endOffsetInclusive: number,
            attributes: any,
        ): GoogleAppsScript.Document.Text;
        setAttributes(attributes: any): GoogleAppsScript.Document.Text;
        setBackgroundColor(
            startOffset: number,
            endOffsetInclusive: number,
            color: string,
        ): GoogleAppsScript.Document.Text;
        setBackgroundColor(color: string): GoogleAppsScript.Document.Text;
        setBold(bold: boolean): GoogleAppsScript.Document.Text;
        setBold(
            startOffset: number,
            endOffsetInclusive: number,
            bold: boolean,
        ): GoogleAppsScript.Document.Text;
        setFontFamily(
            startOffset: number,
            endOffsetInclusive: number,
            fontFamilyName: string,
        ): GoogleAppsScript.Document.Text;
        setFontFamily(fontFamilyName: string): GoogleAppsScript.Document.Text;
        setFontSize(size: number): GoogleAppsScript.Document.Text;
        setFontSize(
            startOffset: number,
            endOffsetInclusive: number,
            size: number,
        ): GoogleAppsScript.Document.Text;
        setForegroundColor(
            startOffset: number,
            endOffsetInclusive: number,
            color: string,
        ): GoogleAppsScript.Document.Text;
        setForegroundColor(color: string): GoogleAppsScript.Document.Text;
        setItalic(italic: boolean): GoogleAppsScript.Document.Text;
        setItalic(
            startOffset: number,
            endOffsetInclusive: number,
            italic: boolean,
        ): GoogleAppsScript.Document.Text;
        setLinkUrl(
            startOffset: number,
            endOffsetInclusive: number,
            url: string,
        ): GoogleAppsScript.Document.Text;
        setLinkUrl(url: string): GoogleAppsScript.Document.Text;
        setStrikethrough(strikethrough: boolean): GoogleAppsScript.Document.Text;
        setStrikethrough(
            startOffset: number,
            endOffsetInclusive: number,
            strikethrough: boolean,
        ): GoogleAppsScript.Document.Text;
        setText(text: string): GoogleAppsScript.Document.Text;
        setTextAlignment(
            startOffset: number,
            endOffsetInclusive: number,
            textAlignment: TextAlignment,
        ): GoogleAppsScript.Document.Text;
        setTextAlignment(
            textAlignment: TextAlignment,
        ): GoogleAppsScript.Document.Text;
        setUnderline(underline: boolean): GoogleAppsScript.Document.Text;
        setUnderline(
            startOffset: number,
            endOffsetInclusive: number,
            underline: boolean,
        ): GoogleAppsScript.Document.Text;
    }

    Hierarchy (View Summary)

    Index

    Methods