Interface Element | Apps Script | Google for Developers (original) (raw)
Google Workspace services
Calendar
- Overview
- CalendarApp
- Classes
- Calendar
- CalendarEvent
- CalendarEventSeries
- EventGuest
- EventRecurrence
- RecurrenceRule
- Enums
- Color
- EventColor
- EventTransparency
- EventType
- GuestStatus
- Visibility
- Advanced services
- Calendar API
Docs
- Overview
- DocumentApp
- Classes
- Body
- Bookmark
- ContainerElement
- Date
- Document
- DocumentTab
- Equation
- EquationFunction
- EquationFunctionArgumentSeparator
- EquationSymbol
- FooterSection
- Footnote
- FootnoteSection
- HeaderSection
- HorizontalRule
- InlineDrawing
- InlineImage
- ListItem
- NamedRange
- PageBreak
- Paragraph
- Person
- Position
- PositionedImage
- Range
- RangeBuilder
- RangeElement
- RichLink
- Tab
- Table
- TableCell
- TableOfContents
- TableRow
- Text
- UnsupportedElement
- Interfaces
- Element
- Enums
- Attribute
- ElementType
- FontFamily
- GlyphType
- HorizontalAlignment
- ParagraphHeading
- PositionedLayout
- TabType
- TextAlignment
- VerticalAlignment
- Advanced services
- Docs API
Drive
- Overview
- DriveApp
- Classes
- File
- FileIterator
- Folder
- FolderIterator
- User
- Enums
- Access
- Permission
- Advanced services
- Drive API
- Drive Activity API
- Drive Labels API
Forms
- Overview
- FormApp
- Classes
- CheckboxGridItem
- CheckboxGridValidation
- CheckboxGridValidationBuilder
- CheckboxItem
- CheckboxValidation
- CheckboxValidationBuilder
- Choice
- DateItem
- DateTimeItem
- DurationItem
- Form
- FormResponse
- GridItem
- GridValidation
- GridValidationBuilder
- ImageItem
- ItemResponse
- ListItem
- MultipleChoiceItem
- PageBreakItem
- ParagraphTextItem
- ParagraphTextValidation
- ParagraphTextValidationBuilder
- QuizFeedback
- QuizFeedbackBuilder
- RatingItem
- ScaleItem
- SectionHeaderItem
- TextItem
- TextValidation
- TextValidationBuilder
- TimeItem
- VideoItem
- Interfaces
- Item
- Enums
- Alignment
- DestinationType
- FeedbackType
- ItemType
- PageNavigationType
- RatingIconType
Gmail
- Overview
- GmailApp
- Classes
- GmailAttachment
- GmailDraft
- GmailLabel
- GmailMessage
- GmailThread
- Advanced services
- Gmail API
Sheets
- Overview
- SpreadsheetApp
- Classes
- Banding
- BooleanCondition
- CellImage
- CellImageBuilder
- Color
- ColorBuilder
- ConditionalFormatRule
- ConditionalFormatRuleBuilder
- ContainerInfo
- DataSource for Connected Sheets
* BigQueryDataSourceSpec
* BigQueryDataSourceSpecBuilder
* DataExecutionStatus
* LookerDataSourceSpec
* LookerDataSourceSpecBuilder
* DataSource
* DataSourceChart
* DataSourceColumn
* DataSourceFormula
* DataSourceParameter
* DataSourcePivotTable
* DataSourceRefreshSchedule
* DataSourceRefreshScheduleFrequency
* DataSourceSheet
* DataSourceSheetFilter
* DataSourceSpec
* DataSourceSpecBuilder
* DataSourceTable
* DataSourceTableColumn
* DataSourceTableFilter - DataValidation
- DataValidationBuilder
- DateTimeGroupingRule
- DeveloperMetadata
- DeveloperMetadataFinder
- DeveloperMetadataLocation
- Drawing
- EmbeddedAreaChartBuilder
- EmbeddedBarChartBuilder
- EmbeddedChart
- EmbeddedChartBuilder
- EmbeddedColumnChartBuilder
- EmbeddedComboChartBuilder
- EmbeddedHistogramChartBuilder
- EmbeddedLineChartBuilder
- EmbeddedPieChartBuilder
- EmbeddedScatterChartBuilder
- EmbeddedTableChartBuilder
- Filter
- FilterCriteria
- FilterCriteriaBuilder
- GradientCondition
- Group
- NamedRange
- OverGridImage
- PageProtection
- PivotFilter
- PivotGroup
- PivotGroupLimit
- PivotTable
- PivotValue
- Protection
- Range
- RangeList
- RichTextValue
- RichTextValueBuilder
- Selection
- Sheet
- Slicer
- SortSpec
- Spreadsheet
- SpreadsheetTheme
- TextFinder
- TextRotation
- TextStyle
- TextStyleBuilder
- ThemeColor
- Enums
- AutoFillSeries
- BandingTheme
- BooleanCriteria
- BorderStyle
- CopyPasteType
- DataValidationCriteria
- DateTimeGroupingRuleType
- DeveloperMetadataLocationType
- DeveloperMetadataVisibility
- Dimension
- Direction
- FrequencyType
- GroupControlTogglePosition
- InterpolationType
- PivotTableSummarizeFunction
- PivotValueDisplayType
- ProtectionType
- RecalculationInterval
- RelativeDate
- SheetType
- SortOrder
- TextDirection
- TextToColumnsDelimiter
- ThemeColorType
- ValueType
- WrapStrategy
- Advanced services
- Sheets API
Slides
- Overview
- SlidesApp
- Classes
- AffineTransform
- AffineTransformBuilder
- AutoText
- Autofit
- Border
- Color
- ColorScheme
- ConnectionSite
- Fill
- Group
- Image
- Layout
- Line
- LineFill
- Link
- List
- ListStyle
- Master
- NotesMaster
- NotesPage
- Page
- PageBackground
- PageElement
- PageElementRange
- PageRange
- Paragraph
- ParagraphStyle
- PictureFill
- Point
- Presentation
- Selection
- Shape
- SheetsChart
- Slide
- SolidFill
- SpeakerSpotlight
- Table
- TableCell
- TableCellRange
- TableColumn
- TableRow
- TextRange
- TextStyle
- ThemeColor
- Video
- WordArt
- Enums
- AlignmentPosition
- ArrowStyle
- AutoTextType
- AutofitType
- CellMergeState
- ContentAlignment
- DashStyle
- FillType
- LineCategory
- LineFillType
- LineType
- LinkType
- ListPreset
- PageBackgroundType
- PageElementType
- PageType
- ParagraphAlignment
- PlaceholderType
- PredefinedLayout
- SelectionType
- ShapeType
- SheetsChartEmbedType
- SlideLinkingMode
- SlidePosition
- SpacingMode
- TextBaselineOffset
- TextDirection
- ThemeColorType
- VideoSourceType
- Advanced services
- Slides API
More...
- Groups
* Overview
* GroupsApp
* Classes
* Group
* Enums
* Role
* Advanced services
* Cloud Identity Groups API
* Migrate from Groups Service - People
* Advanced services
* People API
* Migrate from Contacts service
* Contacts
* Overview
* ContactsApp
* Classes
* AddressField
* CompanyField
* Contact
* ContactGroup
* CustomField
* DateField
* EmailField
* IMField
* PhoneField
* UrlField
* Enums
* ExtendedField
* Field
* Gender
* Priority
* Sensitivity
- Groups
Other Google services
Google Maps
YouTube
- Advanced services
- YouTube Data API
- YouTube Analytics API
- YouTube Content ID API
More...
- Google Ads & Merchant Center
- Google Data Studio
* Overview
* DataStudioApp
* Classes
* BigQueryConfig
* Checkbox
* CommunityConnector
* Config
* DebugError
* Field
* Fields
* GetAuthTypeResponse
* GetDataResponse
* GetSchemaResponse
* Info
* OptionBuilder
* SelectMultiple
* SelectSingle
* SetCredentialsResponse
* TextArea
* TextInput
* UserError
* Enums
* AggregationType
* AuthType
* BigQueryParameterType
* FieldType
Utility services
API & database connections
- JDBC
* Overview
* Jdbc
* Classes
* JdbcArray
* JdbcBlob
* JdbcCallableStatement
* JdbcClob
* JdbcConnection
* JdbcDatabaseMetaData
* JdbcDate
* JdbcParameterMetaData
* JdbcPreparedStatement
* JdbcRef
* JdbcResultSet
* JdbcResultSetMetaData
* JdbcRowId
* JdbcSQLXML
* JdbcSavepoint
* JdbcStatement
* JdbcStruct
* JdbcTime
* JdbcTimestamp
- JDBC
Data usability & optimization
- Optimization
* Overview
* LinearOptimizationService
* Classes
* LinearOptimizationConstraint
* LinearOptimizationEngine
* LinearOptimizationSolution
* Enums
* Status
* VariableType - XML
* Overview
* XmlService
* Classes
* Attribute
* Cdata
* Comment
* DocType
* Document
* Element
* EntityRef
* Format
* Namespace
* ProcessingInstruction
* Text
* Interfaces
* Content
* Enums
* ContentType
- Optimization
HTML & content
- Charts
* Overview
* Charts
* Classes
* AreaChartBuilder
* BarChartBuilder
* Chart
* ChartOptions
* ColumnChartBuilder
* DataTable
* DataTableBuilder
* DataViewDefinition
* DataViewDefinitionBuilder
* LineChartBuilder
* NumberRangeFilterBuilder
* PieChartBuilder
* ScatterChartBuilder
* StringFilterBuilder
* TableChartBuilder
* TextStyle
* TextStyleBuilder
* Interfaces
* DataTableSource
* Enums
* ChartHiddenDimensionStrategy
* ChartMergeStrategy
* ChartType
* ColumnType
* CurveStyle
* MatchType
* Orientation
* PickerValuesLayout
* PointStyle
* Position - HTML
* Overview
* google.script.history (client-side)
* google.script.host (client-side)
* google.script.run (client-side)
* google.script.url (client-side)
* HtmlService
* Classes
* HtmlOutput
* HtmlOutputMetaTag
* HtmlTemplate
* Enums
* SandboxMode
* XFrameOptionsMode
- Charts
Script execution & information
- Base
* Overview
* Browser
* Logger
* MimeType
* Session
* console
* Classes
* Blob
* Menu
* PromptResponse
* RgbColor
* Ui
* User
* Interfaces
* BlobSource
* Enums
* Button
* ButtonSet
* ColorType
* Month
* Weekday - Script
* Overview
* ScriptApp
* Classes
* AuthorizationInfo
* CalendarTriggerBuilder
* ClockTriggerBuilder
* DocumentTriggerBuilder
* FormTriggerBuilder
* Service
* SpreadsheetTriggerBuilder
* StateTokenBuilder
* Trigger
* TriggerBuilder
* Enums
* AuthMode
* AuthorizationStatus
* EventType
* InstallationSource
* TriggerSource
- Base
Script project resources
Manifest
Google Workspace add-ons
Services
- Card
* Overview
* CardService
* Classes
* Action
* ActionResponse
* ActionResponseBuilder
* ActionStatus
* Attachment
* AuthorizationAction
* AuthorizationException
* BorderStyle
* Button
* ButtonSet
* CalendarEventActionResponse
* CalendarEventActionResponseBuilder
* Card
* CardAction
* CardBuilder
* CardHeader
* CardSection
* CardWithId
* Carousel
* CarouselCard
* ChatActionResponse
* ChatClientDataSource
* ChatResponse
* ChatResponseBuilder
* ChatSpaceDataSource
* Chip
* ChipList
* CollapseControl
* Column
* Columns
* ComposeActionResponse
* ComposeActionResponseBuilder
* DatePicker
* DateTimePicker
* DecoratedText
* Dialog
* DialogAction
* Divider
* DriveItemsSelectedActionResponse
* DriveItemsSelectedActionResponseBuilder
* EditorFileScopeActionResponse
* EditorFileScopeActionResponseBuilder
* FixedFooter
* Grid
* GridItem
* HostAppDataSource
* IconImage
* Image
* ImageButton
* ImageComponent
* ImageCropStyle
* KeyValue
* LinkPreview
* MaterialIcon
* Navigation
* Notification
* OpenLink
* OverflowMenu
* OverflowMenuItem
* PlatformDataSource
* SelectionInput
* Suggestions
* SuggestionsResponse
* SuggestionsResponseBuilder
* Switch
* TextButton
* TextInput
* TextParagraph
* TimePicker
* UniversalActionResponse
* UniversalActionResponseBuilder
* UpdateDraftActionResponse
* UpdateDraftActionResponseBuilder
* UpdateDraftBccRecipientsAction
* UpdateDraftBodyAction
* UpdateDraftCcRecipientsAction
* UpdateDraftSubjectAction
* UpdateDraftToRecipientsAction
* UpdatedWidget
* Validation
* Widget
* Enums
* BorderType
* ChipListLayout
* CommonDataSource
* ComposedEmailType
* ContentType
* DisplayStyle
* GridItemLayout
* HorizontalAlignment
* HorizontalSizeStyle
* Icon
* ImageButtonStyle
* ImageCropType
* ImageStyle
* InputType
* Interaction
* LoadIndicator
* OnClose
* OpenAs
* ResponseType
* SelectionInputType
* Status
* SwitchControlType
* TextButtonStyle
* UpdateDraftBodyType
* VerticalAlignment
* WrapStyle - Conferencing Data
* Overview
* ConferenceDataService
* Classes
* ConferenceData
* ConferenceDataBuilder
* ConferenceError
* ConferenceParameter
* EntryPoint
* Enums
* ConferenceErrorType
* EntryPointFeature
* EntryPointType
- Card
Manifest
Apps Script API
v1
- Overview
- REST Resources
- Types
- ExecuteStreamResponse
- ExecutionError
- ExecutionResponse
- File
- LocalizedMessage
- NullValue
Interface Element
Stay organized with collections Save and categorize content based on your preferences.
Element
A generic element. [Document](/apps-script/reference/document/document)
contents are represented as elements. For example, [ListItem](/apps-script/reference/document/list-item)
, [Paragraph](/apps-script/reference/document/paragraph)
, and [Table](/apps-script/reference/document/table)
are elements and inherit all of the methods defined by Element
, such as [getType()](#getType%28%29)
.
Implementing classes
Name | Brief description |
---|---|
Body | The content of a tab in a Google Docs document. |
ContainerElement | A generic element that may contain other elements. |
Date | An element representing a formatted date |
Equation | An element representing a mathematical expression. |
EquationFunction | An element representing a function in a mathematical Equation. |
EquationFunctionArgumentSeparator | An element representing a function separator in a mathematical Equation. |
EquationSymbol | An element representing a symbol in a mathematical Equation. |
FooterSection | An element representing a footer section. |
Footnote | An element representing a footnote. |
FootnoteSection | An element representing a footnote section. |
HeaderSection | An element representing a header section. |
HorizontalRule | An element representing an horizontal rule. |
InlineDrawing | An element representing an embedded drawing. |
InlineImage | An element representing an embedded image. |
ListItem | An element representing a list item. |
PageBreak | An element representing a page break. |
Paragraph | An element representing a paragraph. |
Person | An element representing a link to a person. |
RichLink | An element representing a link to a Google resource, such as a Drive file or a YouTube video. |
Table | An element representing a table. |
TableCell | An element representing a table cell. |
TableOfContents | An element containing a table of contents. |
TableRow | An element representing a table row. |
Text | An element representing a rich text region. |
UnsupportedElement | An element representing a region that is unknown or cannot be affected by a script, such as a page number. |
Detailed documentation
asBody()
Returns the current element as a [Body](/apps-script/reference/document/body)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[Body](/apps-script/reference/document/body)
— The current element.
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asDate()
Returns the current element as a [Date](/apps-script/reference/document/date)
.
When you know an element is a [Date](/apps-script/reference/document/date)
, use this method to set its type as a [Date](/apps-script/reference/document/date)
. Doing so lets autocomplete in the Apps Script editor show you the methods you can use with a [Date](/apps-script/reference/document/date)
.
Return
[Date](/apps-script/reference/document/date)
— The current element with its type set as [Date](/apps-script/reference/document/date)
.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asEquation()
Returns the current element as an [Equation](/apps-script/reference/document/equation)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[Equation](/apps-script/reference/document/equation)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asEquationFunction()
Returns the current element as a [EquationFunction](/apps-script/reference/document/equation-function)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[EquationFunction](/apps-script/reference/document/equation-function)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asEquationFunctionArgumentSeparator()
Returns the current element as a [EquationFunctionArgumentSeparator](/apps-script/reference/document/equation-function-argument-separator)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[EquationFunctionArgumentSeparator](/apps-script/reference/document/equation-function-argument-separator)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asEquationSymbol()
Returns the current element as a [EquationSymbol](/apps-script/reference/document/equation-symbol)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[EquationSymbol](/apps-script/reference/document/equation-symbol)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asHorizontalRule()
Returns the current element as a [HorizontalRule](/apps-script/reference/document/horizontal-rule)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[HorizontalRule](/apps-script/reference/document/horizontal-rule)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asInlineDrawing()
Returns the current element as a [InlineDrawing](/apps-script/reference/document/inline-drawing)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[InlineDrawing](/apps-script/reference/document/inline-drawing)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asInlineImage()
Returns the current element as a [InlineImage](/apps-script/reference/document/inline-image)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[InlineImage](/apps-script/reference/document/inline-image)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asListItem()
Returns the current element as a [ListItem](/apps-script/reference/document/list-item)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[ListItem](/apps-script/reference/document/list-item)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asPageBreak()
Returns the current element as a [PageBreak](/apps-script/reference/document/page-break)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[PageBreak](/apps-script/reference/document/page-break)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asParagraph()
Returns the current element as a [Paragraph](/apps-script/reference/document/paragraph)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[Paragraph](/apps-script/reference/document/paragraph)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asPerson()
Returns the current element as a [Person](/apps-script/reference/document/person)
.
When you know an element is a [Person](/apps-script/reference/document/person)
, use this method to set its type as a person. Doing so lets autocomplete in the Apps Script editor show you the methods you can use with a person element.
Return
[Person](/apps-script/reference/document/person)
— The current element with its type set as [Person](/apps-script/reference/document/person)
.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asRichLink()
Returns the current element as a [RichLink](/apps-script/reference/document/rich-link)
, for example, a link to a Google Sheets file.
When you know an element is a [RichLink](/apps-script/reference/document/rich-link)
, use this method to set its type as a [RichLink](/apps-script/reference/document/rich-link)
. Doing so lets autocomplete in the Apps Script editor show you the methods you can use with a [RichLink](/apps-script/reference/document/rich-link)
.
Return
[RichLink](/apps-script/reference/document/rich-link)
— The current element with its type set as [RichLink](/apps-script/reference/document/rich-link)
.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asTable()
Returns the current element as a [Table](/apps-script/reference/document/table)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[Table](/apps-script/reference/document/table)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asTableCell()
Returns the current element as a [TableCell](/apps-script/reference/document/table-cell)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[TableCell](/apps-script/reference/document/table-cell)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asTableOfContents()
Returns the current element as a [TableOfContents](/apps-script/reference/document/table-of-contents)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[TableOfContents](/apps-script/reference/document/table-of-contents)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asTableRow()
Returns the current element as a [TableRow](/apps-script/reference/document/table-row)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[TableRow](/apps-script/reference/document/table-row)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
asText()
Returns the current element as a [Text](/apps-script/reference/document/text)
.
Use this method to aid auto-complete whenever a given element is known to be of a specific type.
Return
[Text](/apps-script/reference/document/text)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
copy()
Returns a detached, deep copy of the current element.
Any child elements present in the element are also copied. The new element doesn't have a parent.
Return
[Element](#)
— The new copy.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
getAttributes()
Retrieves the element's attributes.
The result is an object containing a property for each valid element attribute where each property name corresponds to an item in the DocumentApp.Attribute
enumeration.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody();
// Append a styled paragraph. const par = body.appendParagraph('A bold, italicized paragraph.'); par.setBold(true); par.setItalic(true);
// Retrieve the paragraph's attributes. const atts = par.getAttributes();
// Log the paragraph attributes.
for (const att in atts) {
Logger.log(${att}:${atts[att]}
);
}
Return
Object
— The element's attributes.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
getNextSibling()
Retrieves the element's next sibling element.
The next sibling has the same parent and follows the current element.
Return
[Element](#)
— The next sibling element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
getParent()
Retrieves the element's parent element.
The parent element contains the current element.
Return
[ContainerElement](/apps-script/reference/document/container-element)
— The parent element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
getPreviousSibling()
Retrieves the element's previous sibling element.
The previous sibling has the same parent and precedes the current element.
Return
[Element](#)
— The previous sibling element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
getType()
Retrieves the element's [ElementType](/apps-script/reference/document/element-type)
.
Use getType()
to determine the exact type of a given element.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody();
// Obtain the first element in the active tab's body.
const firstChild = body.getChild(0);
// Use getType() to determine the element's type. if (firstChild.getType() === DocumentApp.ElementType.PARAGRAPH) { Logger.log('The first element is a paragraph.'); } else { Logger.log('The first element is not a paragraph.'); }
Return
[ElementType](/apps-script/reference/document/element-type)
— The element type.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
isAtDocumentEnd()
Determines whether the element is at the end of the [Document](/apps-script/reference/document/document)
.
Return
Boolean
— Whether the element is at the end of the tab.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
merge()
Merges the element with the preceding sibling of the same type.
Only elements of the same [ElementType](/apps-script/reference/document/element-type)
can be merged. Any child elements contained in the current element are moved to the preceding sibling element.
The current element is removed from the document.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody();
// Example 1: Merge paragraphs // Append two paragraphs to the document's active tab. const par1 = body.appendParagraph('Paragraph 1.'); const par2 = body.appendParagraph('Paragraph 2.'); // Merge the newly added paragraphs into a single paragraph. par2.merge();
// Example 2: Merge table cells // Create a two-dimensional array containing the table's cell contents. const cells = [ ['Row 1, Cell 1', 'Row 1, Cell 2'], ['Row 2, Cell 1', 'Row 2, Cell 2'], ]; // Build a table from the array. const table = body.appendTable(cells); // Get the first row in the table. const row = table.getRow(0); // Get the two cells in this row. const cell1 = row.getCell(0); const cell2 = row.getCell(1); // Merge the current cell into its preceding sibling element. const merged = cell2.merge();
Return
[Element](#)
— The merged element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
removeFromParent()
Removes the element from its parent.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody();
// Remove all images in the active tab's body. const imgs = body.getImages(); for (let i = 0; i < imgs.length; i++) { imgs[i].removeFromParent(); }
Return
[Element](#)
— The removed element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
setAttributes(attributes)
Sets the element's attributes.
The specified attributes parameter must be an object where each property name is an item in the DocumentApp.Attribute
enumeration and each property value is the new value to be applied.
const doc = DocumentApp.getActiveDocument(); const documentTab = doc.getActiveTab().asDocumentTab(); const body = documentTab.getBody();
// Define a custom paragraph style. const style = {}; style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.RIGHT; style[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri'; style[DocumentApp.Attribute.FONT_SIZE] = 18; style[DocumentApp.Attribute.BOLD] = true;
// Append a plain paragraph. const par = body.appendParagraph('A paragraph with custom style.');
// Apply the custom style. par.setAttributes(style);
Parameters
Name | Type | Description |
---|---|---|
attributes | Object | The element's attributes. |
Return
[Element](#)
— The current element.
Authorization
Scripts that use this method require authorization with one or more of the following scopes:
https://www.googleapis.com/auth/documents.currentonly
https://www.googleapis.com/auth/documents
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-03 UTC.