 | OO-Snippets: Enumerate contentCommons| Keywords | paragraph, enumeration, text, createEnumeration, createContentEnumeration, TextContent, TextGraphicObject, getAvailableServiceNames |
|---|
| Language | OOBasic |
|---|
| Application | Writer |
|---|
| Authors | Andrew
Pitonyak (initial)
|
|---|
| Supported Versions | |
|---|
| Supported OS | |
|---|
| Question |
How can I enumerate the content in a Writer document and identify the
contained graphics images?
|
|---|
| Answer |
The primary reason to enumerate text content is to export the document.
I was recently asked how to recognize graphics objects embedded in the
text. The FindGraphics macro finds graphics objects that are anchored to
a paragraph, anchored to a character, and inserted as a character. This
does not find images anchored to the page.
|
|---|
Sub FindGraphics
Dim oParEnum
Dim oPar
Dim oSectionEnum
Dim oSection
Dim oContentEnum
Dim oContent
oParEnum = ThisComponent.getText().createEnumeration()
Do While oParEnum.hasMoreElements()
oPar = oParEnum.nextElement()
If oPar.supportsService("com.sun.star.text.Paragraph") Then
oContentEnum = oPar.createContentEnumeration("com.sun.star.text.TextContent")
Do While oContentEnum.hasMoreElements()
oContent = oContentEnum.nextElement()
If oContent.supportsService("com.sun.star.text.TextGraphicObject") Then
Print "Found a graphic object anchored to a Paragraph"
End If
Loop
oSectionEnum = oPar.createEnumeration()
Do While oSectionEnum.hasMoreElements()
oSection = oSectionEnum.nextElement()
If oSection.TextPortionType = "Text" Then
ElseIf oSection.TextPortionType = "Frame" Then
oContentEnum = oSection.createContentEnumeration("com.sun.star.text.TextGraphicObject")
Do While oContentEnum.hasMoreElements()
oContent = oContentEnum.nextElement()
If oContent.supportsService("com.sun.star.text.TextGraphicObject") Then
Print "Found a graphic object anchored to or as a character"
End If
Loop
End If
Loop
End If
Loop
End Sub
|
Changelog| Date | User | Modification |
|---|
| 2004-06-24 | and | Initial version |
|