You can find the code for the BASIC-Filter below and the document template with the macro attached.
ConvertTreepad2Writer
Converts Treepag Light 3.0 (.hjt) Files into OpenOffice Writer Files.
Preserves the tree structure by formatting the node headings with paragraph format "Heading 1".."Heading 9".
The document has Liberation Sans 12pt as default formatting and heading sizes ranging from 12pt-26pt.
This was written with OpenOffice 3.0. I do not know if it works with other OpenOffice versions.
Instruction for using the Document-Template and the script:
Open the "ConvertTreepad2Writer" document template.
Open Treepad .hjt-File in Writer with Insert/File. My Treepad file was created under Windows, so the import parameters were:
Character Encoding: Western Europe (Windows 1252)
Paragraph Break: CR & LF
The first node in the file with tree-level 0 must be removed manually before running the script.
Run the script with the “ConvertTreepad2Writer” Button in the “Macro” Toolbar. This will format Node headings according to the hierarchy in the Treepad tree. The Treepad database structure will be removed from the text.
This is the code for the filter:
Code: Select all
Sub ConvertTreepad2Writer()
Dim Doc As Object
Dim Enum As Object
Dim ParagraphObject As Object
Dim ParagraphString As String
Dim HeadingObject As Object
Dim LevelObject As Object
Dim ParagraphTemplate As String
Doc = StarDesktop.CurrentComponent
Enum = Doc.Text.createEnumeration
' loop over all paragraphs
While Enum.hasMoreElements
'Assign next paragraph to object variable
ParagraphObject = Enum.nextElement
ParagraphString = ParagraphObject.String
'Remove Treepad structure
If InStr(ParagraphString,"dT=Text") Then Doc.Text.removeTextContent(ParagraphObject)
If InStr(ParagraphString,"<end node>") Then Doc.Text.removeTextContent(ParagraphObject)
'If the current paragraph contains the string "<node>" then the following paragraph will be the node heading,
'followed by level of tree-depth
If InStr(ParagraphString,"<node>") Then
'Assign Heading and tree-level to object variables
HeadingObject = Enum.nextElement
LevelObject = Enum.nextElement
'Construct the paragraph template name. This will work only for tree-depths from 1..9
ParagraphTemplate = "Heading " & Left(LevelObject.String,1)
'Assign the paragraph template to the heading according to the tree-depth level
HeadingObject.ParaStyleName = ParagraphTemplate
'Remove <node> paragraph
Doc.Text.removeTextContent(ParagraphObject)
'Remove Paragraph with nodelevel
Doc.Text.removeTextContent(LevelObject)
End If
Wend
End Sub