Document JavaScript API

Documents editor supports advanced JavaScript APIs.

Class DocumentApp

Enumerations:
ElementType:{      
              BODY:           2,       
              PARAGRAPH:      4,         
              TEXT:           8,       
              UNSUPPORTED:    1024 
          }
Methods:
clearChangeHistory()
Clear the Track Change history and accept all changes.
disableTrackChange()
Turn off Track Change. The future changes will not be recorded as history.
enableTrackChange()
Start tracking of the document. The changes will be recorded.
getBody()
Get the Body instance.
getCursor(callback)
callback is user defined function that will be called asynchronously upon receiving Docs response.
Get current cursor position.
getName(callback)
callback is user defined function that will be called asynchronously upon receiving Docs response.
Get document title.
getSelection(callback)
callback is user defined function that will be called asynchronously upon receiving Docs response.
Get current cursor selection.
save()
Save the document to file repository with a new file version.
setCursor(position)
position is a Position instance that is associated with one paragraph and its offset.
Set current cursor to this position.
setSelection(range)
range is an instance of DocumentApp.Range.
Set current selection to this range.

Class Element, Class ContainerElement, Class Text, Class UnSupportedElement

Methods:
Element(id)
id one is the string id.
Create an Element object.
getId()
Return the string id that represents this element.
getParent(callback)
callback is user defined function that will be called asynchronously upon receiving Docs response.
Get the parent of this element. The parent is one ContainerElement instance.
getNextSibling(callback)
callback is user defined function that will be called asynchronously upon receiving Docs response.
Get the next sibling of this element.
getPrevSibling(callback)
callback is user defined function that will be called asynchronously upon receiving Docs response.
Get the previous sibling of this element.

Class ContainerElement, Class Body, and Class Paragraph

Methods:
ContainerElement(id)
id is the string id that represents this container element.
Create a ContainerElement object.
editAsText()
Get a Text instance that contains text content in this container element.
getChild(index, callback)
index is an integer.
callback is user defined function that will be called asynchronously upon receiving Docs response.
Get the child that is specified by this index.
getNumChildren(callback)
callback is user defined function that will be called asynchronously upon receiving Docs response.
Get the number of its children.

Class Paragraph

Methods:
Paragraph(id)
id is the string id that represents this paragraph.
Create a Paragraph object.
appendText(text, callback)
text is the plain text.
callback is user defined function that will be called asynchronously upon receiving Docs response.
Get a Text instance that contains text content in this container element.
getChild(index, callback)
index is an integer.
callback is user defined function that will be called asynchronously upon receiving Docs response.
Get the child that is specified by this index.
getNumChildren(callback)
callback is user defined function that will be called asynchronously upon receiving Docs response.
Append the plain text at the end of this paragraph.
clear()
Clear the text content of this paragraph.
getText(callback)
callback is user defined function that will be called asynchronously upon receiving Docs response.
Get the plain text of this paragraph.
setText(text)
text is plain text.
Set this plain text as the text content of this paragraph.

Class Body

Methods:
Body()
Create one Body object, one singleton instance.
appendParagraph(text, callback)
text is the paragraph context in string.
callback is user defined function that will be called asynchronously upon receiving Docs response.
Create a new paragraph with text as its content, append the new paragraph after the last paragraph in body.
getParagraphs(callback)
callback is user defined function that will be called asynchronously upon receiving Docs response.
Get all paragraphs of this document body.
insertParagraph(index, text, callback)
text is the pargraph content in string.
callback is user defined function that will be called asynchronously upon receiving Docs response.
Create one new paragraph with text as its content, insert the new paragraph at this index of paragraphs of this body.

Class Text

Methods:
Text(parent, start, length)
parent is a container element instance that contains this object, usually it is one paragraph instance.
start(optional) is an integer index. It is the start position if the text is one text portion.
length(optional) is an integer, text length.
Create a Text object.
appendText(text, callback)
text is the text content in string.
callback is user defined function that will be called asynchronously upon receiving Docs response.
Append text at the end of this Text object.
clear()
Clear the text content.
getParent()
Get its parent of this object.
getText()
Get plain text of this object.
insertText(offset, text, callback)
text is the text content in string.
callback is user defined function that will be called asynchronously upon receiving Docs response.
Insert text at this offset of this Text object.
setText(text)
text is plain text.
Set the plain text as text content of this object.

Class Position

Methods:
Position(element, offset)
element is a container element instance, usually it is one paragraph instance.
offset is the offset within this element.
Create a Position object.
getElement()
Get its element that this position belongs to.
getOffset()
Get the offset information.
insertText(text)
text is the plain text.
Insert plain text at this position.

Class DocumentApp.Range

Methods:
Range(start, end)
start is the start position of this range.
end(optional) is the end position of this range.
Create a DocumentApp.Range object.
buildRange(start, end)
start is start position of this range.
end(optional) is the end position of this range.
Create a DocumentApp.Range object.