table of contents contents Matthias Prem How can I insert a Table of Contents? /* 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~{%see com.sun.star.text.XTextDocument%XTextDocument} /* retrieve XMultiServiceFactory to get the ContentIndex */ xServiceManager=oDoc~{%see com.sun.star.lang.XMultiServiceFactory%XMultiServiceFactory} toc = xServiceManager~createInstance("{%see com.sun.star.text.ContentIndex}") /* access the properties: level 10, use headings */ tocPS = toc~{%see com.sun.star.beans.XPropertySet%XPropertySet} tocPS~setPropertyValue("Level", box("Short", "10")) tocPS~setPropertyValue("CreateFromOutline", box("boolean" ,.true)) /* get the text content of toc and insert it */ tocTC = toc~{%see com.sun.star.text.XTextContent%XTextContent}() xText=xTextDoc~getText() xCursor=xTextDoc~getText~createTextCursor() xText~insertTextContent(xCursor, tocTC, .false) /* retrieve XDocumentIndex and update it */ xDocIndex=toc~{%see com.sun.star.text.XDocumentIndex%XDocumentIndex} xDocIndex~update() ::requires UNO.CLS Initial version