<?xml version="1.0"?> | |
<!-- | |
$RCSfile: Writer.TableOfContents.snip,v $ | |
last change: $Revision: 1.1 $ $Author: tomsontom $ $Date: 2006/07/14 09:36:46 $ | |
(c)2003 by the copyright holders listed with the author-tags. | |
If no explicit copyright holder is mentioned with a certain author, | |
the author him-/herself is the copyright holder. All rights reserved. | |
Public Documentation License Notice: | |
The contents of this Documentation are subject to the | |
Public Documentation License Version 1.0 (the "License"); | |
you may only use this Documentation if you comply with | |
the terms of this License. A copy of the License is | |
available at http://www.openoffice.org/licenses/PDL.html | |
The Original Documentation can be found in the CVS archives | |
of openoffice.org at the place specified by RCSfile: in this header. | |
The Initial Writer(s) of the Original Documentation are listed | |
with the author-tags below. | |
The Contributor(s) are listed with the author-tags below | |
without the marker for being an initial author. | |
All Rights Reserved. | |
--> | |
<snippet language="ooRexx" application="Writer"> | |
<keywords> | |
<keyword>table of contents</keyword> | |
<keyword>contents</keyword> | |
</keywords> | |
<authors> | |
<author id="matthiasprem" initial="true" email="h0252896@wu-wien.ac.at">Matthias Prem</author> | |
</authors> | |
<question heading="Table of Contents">How can I insert a Table of Contents? | |
</question> | |
<answer> | |
<listing>/* 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</listing> | |
</answer> | |
<versions> | |
<version number="2.0.x" status="tested"/> | |
</versions> | |
<operating-systems> | |
<operating-system name="All"/> | |
</operating-systems> | |
<changelog> | |
<change author-id="matthiasprem" date="2006-07-10">Initial version</change> | |
</changelog> | |
</snippet> |