LibreOffice and OpenOffice programs may be automated through macros. Various languages are possible. This module provides some notes and gives links to the relevant web pages.
Summary: LibreOffice and OpenOffice programs may be automated through macros. Various languages are possible. This module provides some notes and gives links to the relevant web pages.
LibreOffice and OpenOffice programs may be automated through macros. Various languages are possible. This module provides some notes and gives links to the relevant web pages.
http://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Structure_of_Text_Documents
The document explains how to access paragraphs and character properties, shows how to traverse a document and how to export certain features of the text as HTML.
http://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Editing_Text_Documents
Dealing with tables, bookmarks, anchors and other text elements
Change the settings to allow macro recording. Recording macros is useful to learn about macro programming.
The example demonstrates how enumeration of paragraphs is done and how properties of text elements are queried.
' ===== LibreOffice BASIC =====
Sub Main
Dim FileNo As Integer
Dim Filename As String
Dim CurLine As String
Dim Doc As Object
Dim Enum1 As Object, Enum2 As Object
Dim TextElement As Object, TextPortion As Object
Filename = "c:\temp\text.html"
FileNo = Freefile
Open Filename For Output As #FileNo
Print #FileNo, "<html><body>"
Doc = ThisComponent
Enum1 = Doc.Text.createEnumeration
' loop over all paragraphs
While Enum1.hasMoreElements
TextElement = Enum1.nextElement
If TextElement.supportsService("com.sun.star.text.Paragraph") Then
Enum2 = TextElement.createEnumeration
CurLine = "<p>"
' loop over all paragraph portions
While Enum2.hasMoreElements
TextPortion = Enum2.nextElement
If TextPortion.CharWeight = com.sun.star.awt.FontWeight.BOLD THEN
CurLine = CurLine & "<b>" & TextPortion.String & "</b>"
Else
CurLine = CurLine & TextPortion.String
End If
Wend
' output the line
CurLine = CurLine & "</p>"
Print #FileNo, CurLine
End If
Wend
' write HTML footer
Print #FileNo, "</body></html>"
Close #FileNo
End Sub