OO-Snippets: Table of Contents

Commons

Keywordstable of contents, contents
LanguageooRexx
ApplicationWriter
AuthorsMatthias Prem (initial)
Supported Versions2.0.x  
Supported OSAll  
QuestionHow can I insert a Table of Contents?
Answer

Code-Snippet-Listing (snippet-source)

/* TableOfContents.rex */
/* Macro */
/* inserts a table of contents in a given document */

/* get the script context, the document service and the XTextDocument */
xScriptContext=uno.getScriptContext()
oDoc=xScriptContext~getDocument
xTextDoc=oDoc~XTextDocument

/* retrieve XMultiServiceFactory to get the ContentIndex */
xServiceManager=oDoc~XMultiServiceFactory
toc = xServiceManager~createInstance("com.sun.star.text.ContentIndex")

/* access the properties: level 10, use headings */
tocPS = toc~XPropertySet
tocPS~setPropertyValue("Level", box("Short", "10"))
tocPS~setPropertyValue("CreateFromOutline", box("boolean" ,.true))

/* get the text content of toc and insert it */
tocTC = toc~XTextContent()
xText=xTextDoc~getText()
xCursor=xTextDoc~getText~createTextCursor()
xText~insertTextContent(xCursor, tocTC, .false)

/* retrieve XDocumentIndex and update it */
xDocIndex=toc~XDocumentIndex
xDocIndex~update()

::requires UNO.CLS

Changelog

DateUserModification
2006-07-10matthiaspremInitial version

and