Class Table - Apps Script - Google Developers
Class Table - Apps Script - Google Developers
1 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
Class Table
An element representing a table. A Table may only contain TableRow elements. For more
information on document structure, see the guide to extending Google Docs.
When creating a Table that contains a large number of rows or cells, consider building it from a
string array, as shown in the following example.
Methods
Method
Return type
Brief description
appendTableRow()
TableRow
appendTableRow(tableRow)
TableRow
clear()
Table
copy()
Table
editAsText()
Text
findElement(elementType)
RangeElement
findElement(elementType,
from)
RangeElement
findText(searchPattern)
RangeElement
12/26/2015 8:01 PM
2 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
findText(searchPattern,
from)
RangeElement
getAttributes()
Object
getBorderColor()
String
getBorderWidth()
Number
getCell(rowIndex,
cellIndex)
TableCell
getChild(childIndex)
Element
getChildIndex(child)
Integer
getColumnWidth(
columnIndex)
Number
getLinkUrl()
String
getNextSibling()
Element
getNumChildren()
Integer
getNumRows()
Integer
getParent()
getPreviousSibling()
Element
getRow(rowIndex)
TableRow
getText()
String
getTextAlignment()
TextAlignment
getType()
ElementType
insertTableRow(childIndex) TableRow
insertTableRow(childIndex, TableRow
tableRow)
isAtDocumentEnd()
Boolean
removeChild(child)
Table
12/26/2015 8:01 PM
3 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
removeFromParent()
Table
removeRow(rowIndex)
TableRow
replaceText(searchPattern, Element
replacement)
setAttributes(attributes) Table
setBorderColor(color)
Table
setBorderWidth(width)
Table
setColumnWidth(
columnIndex, width)
Table
setLinkUrl(url)
Table
setTextAlignment(
textAlignment)
Table
Detailed documentation
appendTableRow()
Creates and appends a new TableRow.
Return
TableRow the new table row element
appendTableRow(tableRow)
Appends the given TableRow.
Parameters
Name
Type
Description
tableRow
TableRow
12/26/2015 8:01 PM
4 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
Return
TableRow the appended table row element
clear()
Clears the contents of the element.
Return
Table the current element
copy()
Returns a detached, deep copy of the current element.
Any child elements present in the element are also copied. The new element will not have a
parent.
Return
Table the new copy
editAsText()
Obtains a Text version of the current element, for editing.
Use editAsText for manipulating the elements contents as rich text. The editAsText mode
ignores non-text elements (such as InlineImage and HorizontalRule).
Child elements fully contained within a deleted text range are removed from the element.
12/26/2015 8:01 PM
5 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
// Delete " sample.\n\n An" removing the horizontal rule in the process.
body.editAsText().deleteText(14, 25);
Return
Text a text version of the current element
findElement(elementType)
Searches the contents of the element for a descendant of the speci ed type.
Parameters
Name
Type
Description
elementType
ElementType
Return
RangeElement a search result indicating the position of the search element
findElement(elementType, from)
Searches the contents of the element for a descendant of the speci ed type, starting from the
speci ed RangeElement.
12/26/2015 8:01 PM
6 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
if (par.getHeading() == searchHeading) {
// Found one, update and stop.
par.setText('This is the first header.');
return;
}
}
Parameters
Name
Type
Description
elementType
ElementType
from
RangeElement
Return
RangeElement a search result indicating the next position of the search element
findText(searchPattern)
Searches the contents of the element for the speci ed text pattern using regular expressions.
A subset of the JavaScript regular expression features are not fully supported, such as capture
groups and mode modi ers.
The provided regular expression pattern is independently matched against each text block
contained in the current element.
Parameters
Name
Type
Description
searchPattern
String
Return
RangeElement a search result indicating the position of the search text, or null if there is no
match
12/26/2015 8:01 PM
7 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
findText(searchPattern, from)
Searches the contents of the element for the speci ed text pattern, starting from a given search
result.
A subset of the JavaScript regular expression features are not fully supported, such as capture
groups and mode modi ers.
The provided regular expression pattern is independently matched against each text block
contained in the current element.
Parameters
Name
Type
Description
searchPattern
String
from
RangeElement
Return
RangeElement a search result indicating the next position of the search text, or null if there is
no match
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.
12/26/2015 8:01 PM
8 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
Return
Object the element's attributes
getBorderColor()
Retrieves the border color.
Return
String the border color
getBorderWidth()
Retrieves the border width, in points.
Return
Number the border width, in points
getCell(rowIndex, cellIndex)
Retrieves the TableCell at the speci ed row and cell indices.
Parameters
Name
Type
Description
rowIndex
Integer
cellIndex
Integer
12/26/2015 8:01 PM
9 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
Return
TableCell the table cell
getChild(childIndex)
Retrieves the child element at the speci ed child index.
Parameters
Name
Type
Description
childIndex
Integer
Return
Element the child element at the speci ed index
getChildIndex(child)
Retrieves the child index for the speci ed child element.
Parameters
Name
Type
Description
12/26/2015 8:01 PM
10 of 19
child
Element
https://developers.google.com/apps-script/reference/document/table#fi...
Return
Integer the child index
getColumnWidth(columnIndex)
Retrieves the width of the speci ed table column, in points.
Parameters
Name
Type
Description
columnIndex
Integer
Return
Number the column width, in points
getLinkUrl()
Retrieves the link url.
Return
String the link url, or null if the element contains multiple values for this attribute
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
12/26/2015 8:01 PM
11 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
getNumChildren()
Retrieves the number of children.
Return
Integer the number of children
getNumRows()
Retrieves the number of TableRows.
Return
Integer the number of table rows
getParent()
Retrieves the element's parent element.
The parent element contains the current element.
Return
ContainerElement the parent element
getPreviousSibling()
12/26/2015 8:01 PM
12 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
Return
Element the previous sibling element
getRow(rowIndex)
Retrieves the TableRow at the speci ed row index.
Parameters
Name
Type
Description
rowIndex
Integer
Return
TableRow the table row
getText()
Retrieves the contents of the element as a text string.
Return
String the contents of the element as text string
getTextAlignment()
Gets the text alignment. The available types of alignment are
DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPT, and
DocumentApp.TextAlignment.SUPERSCRIPT.
Return
12/26/2015 8:01 PM
13 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
TextAlignment the type of text alignment, or null if the text contains multiple types of text
alignments or if the text alignment has never been set
getType()
Retrieves the element's ElementType.
Use getType() to determine the exact type of a given element.
Return
ElementType the element type
insertTableRow(childIndex)
Creates and inserts a new TableRow at the speci ed index.
Parameters
Name
Type
Description
childIndex
Integer
Return
12/26/2015 8:01 PM
14 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
insertTableRow(childIndex, tableRow)
Inserts the given TableRow at the speci ed index.
Parameters
Name
Type
Description
childIndex
Integer
tableRow
TableRow
Return
TableRow the inserted table row element
isAtDocumentEnd()
Determines whether the element is at the end of the Document.
Return
Boolean whether the element is at the end of the document
removeChild(child)
Removes the speci ed child element.
Parameters
Name
Type
Description
child
Element
Return
12/26/2015 8:01 PM
15 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
removeFromParent()
Removes the element from its parent.
Return
Table the removed element
removeRow(rowIndex)
Removes the TableRow at the speci ed row index.
Parameters
Name
Type
Description
rowIndex
Integer
Return
TableRow the removed row
replaceText(searchPattern, replacement)
Replaces all occurrences of a given text pattern with a given replacement string, using regular
expressions.
12/26/2015 8:01 PM
16 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
A subset of the JavaScript regular expression features are not fully supported, such as capture
groups and mode modi ers.
The provided regular expression pattern is independently matched against each text block
contained in the current element.
Parameters
Name
Type
Description
searchPattern
String
replacement
String
Return
Element the current element
setAttributes(attributes)
Sets the element's attributes.
The speci ed 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.
12/26/2015 8:01 PM
17 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
Parameters
Name
Type
Description
attributes
Object
Return
Table the current element
setBorderColor(color)
Sets the border color.
Parameters
Name
Type
Description
color
String
Return
Table the current element
setBorderWidth(width)
Sets the border width, in points.
Parameters
12/26/2015 8:01 PM
18 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
Name
Type
Description
width
Number
Return
Table the current element
setColumnWidth(columnIndex, width)
Sets the width of the speci ed column, in points.
Parameters
Name
Type
Description
columnIndex
Integer
width
Number
Return
Table the current element
setLinkUrl(url)
Sets the link url.
Parameters
Name
Type
Description
url
String
Return
Table the current element
12/26/2015 8:01 PM
19 of 19
https://developers.google.com/apps-script/reference/document/table#fi...
setTextAlignment(textAlignment)
Sets the text alignment. The available types of alignment are
DocumentApp.TextAlignment.NORMAL, DocumentApp.TextAlignment.SUBSCRIPT, and
DocumentApp.TextAlignment.SUPERSCRIPT.
Parameters
Name
Type
Description
textAlignment
TextAlignment
Return
Table the current element
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and
code samples are licensed under the Apache 2.0 License. For details, see our Site Policies.
Last updated May 19, 2015.
12/26/2015 8:01 PM