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.
- getName(callback)
- callback is user defined function that will be called asynchronously upon receiving Docs response.
- getSelection(callback)
- callback is user defined function that will be called asynchronously upon receiving Docs response.
- 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.
- setSelection(range)
- range is an instance of DocumentApp.Range.
Class Element, Class ContainerElement, Class Text, Class UnSupportedElement
Methods:
- Element(id)
- id one is the string id.
- 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.
- getNextSibling(callback)
- callback is user defined function that will be called asynchronously upon receiving Docs response.
- getPrevSibling(callback)
- callback is user defined function that will be called asynchronously upon receiving Docs response.
Class ContainerElement, Class Body, and Class Paragraph
Methods:
- ContainerElement(id)
- id is the string id that represents this container element.
- editAsText()
- Get a Text instance that contains text content in this container element.
- getChild(index, callback)
- index is an integer.
- getNumChildren(callback)
- callback is user defined function that will be called asynchronously upon receiving Docs response.
Class Paragraph
Methods:
- Paragraph(id)
- id is the string id that represents this paragraph.
- appendText(text, callback)
- text is the plain text.
- getChild(index, callback)
- index is an integer.
- getNumChildren(callback)
- callback is user defined function that will be called asynchronously upon receiving Docs response.
- clear()
- Clear the text content of this paragraph.
- getText(callback)
- callback is user defined function that will be called asynchronously upon receiving Docs response.
- setText(text)
- text is plain text.
Class Body
Methods:
- Body()
- Create one Body object, one singleton instance.
- appendParagraph(text, callback)
- text is the paragraph context in string.
- getParagraphs(callback)
- callback is user defined function that will be called asynchronously upon receiving Docs response.
- insertParagraph(index, text, callback)
- text is the pargraph content in string.
Class Text
Methods:
- Text(parent, start, length)
- parent is a container element instance that contains this object, usually it is one paragraph instance.
- appendText(text, callback)
- text is the text content in string.
- 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.
- setText(text)
- text is plain text.
Class Position
Methods:
- Position(element, offset)
- element is a container element instance, usually it is one paragraph instance.
- getElement()
- Get its element that this position belongs to.
- getOffset()
- Get the offset information.
- insertText(text)
- text is the plain text.
Class DocumentApp.Range
Methods:
- Range(start, end)
- start is the start position of this range.
- buildRange(start, end)
- start is start position of this range.