 | OO-Snippets: Create and insert or modify an existing table of contents or indexCommons| Keywords | index, table of contents, ContentIndex, getDocumentIndexes, CreateFromOutline |
|---|
| Language | OOBasic |
|---|
| Application | Writer |
|---|
| Authors | Andrew Pitonyak (initial)
|
|---|
| Supported Versions | |
|---|
| Supported OS | |
|---|
| Question |
How can I insert a table of contents into my document?
|
|---|
| Answer |
Create a com.sun.star.text.ContentIndex from the document and then
insert the text content.
Be certain to set the appropriate properties. I have some discussion
at: http://www.oooforum.org/forum/viewtopic.php?t=10251 |
|---|
Sub InsertATOC
Dim oCurs
Dim oIndexes
Dim oIndex
Dim i As Integer
Dim bIndexFound As Boolean
oIndexes = ThisComponent.getDocumentIndexes()
bIndexFound = False
For i = 0 To oIndexes.getCount() - 1
oIndex = oIndexes.getByIndex(i)
If oIndex.supportsService("com.sun.star.text.ContentIndex") Then
bIndexFound = True
Exit For
End If
Next
If Not bIndexFound Then
Print "I did not find an existing content index"
contain
oIndex = ThisComponent.createInstance("com.sun.star.text.ContentIndex")
oIndex.CreateFromOutline = True
oCurs = ThisComponent.getText().createTextCursor()
oCurs.gotoStart(False)
ThisComponent.getText().insertTextContent(oCurs, oIndex, False)
End If
oIndex.update()
End Sub
|
Changelog| Date | User | Modification |
|---|
| 2004-06-29 | pitonyak | Initial version |
|