Okay... answering my own question somewhat. Using the wonderful guide to macros by
Andrew Pitonyak, I derived a few methods to help out:
Code: Select all
Sub WriteString( data as String, txt as Object, cursor as Object, bold as Boolean, underline as Boolean, italics as Boolean )
SetStyle( cursor, bold, underline, italics )
txt.insertString( cursor, data, FALSE )
End Sub
Sub Endl( txt as Object, cursor as Object )
txt.insertControlCharacter( cursor, com.sun.star.text.ControlCharacter.LINE_BREAK, FLASE )
End Sub
Sub Endp( txt as Object, cursor as Object )
txt.insertControlCharacter( cursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, FLASE )
End Sub
Sub SetStyle( cursor as Object, bold as Boolean, underline as Boolean, italics as Boolean )
if bold then
cursor.CharWeight = com.sun.star.awt.FontWeight.BOLD
else
cursor.CharWeight = com.sun.star.awt.FontWeight.NORMAL
end if
if underline then
cursor.CharUnderline = com.sun.star.awt.FontUnderline.SINGLE
else
cursor.CharUnderline = com.sun.star.awt.FontUnderline.NONE
end if
if italics then
cursor.CharPosture = com.sun.star.awt.FontSlant.ITALIC
else
cursor.CharPosture = com.sun.star.awt.FontSlant.NONE
end if
End Sub
Mind you, this is for very simple formatting only, your mileage may vary.
Then, to invoke said code, I set up the document parameter, connect to the database, and loop:
Code: Select all
Sub PrintGuide
Dim oDoc As Object
Dim oText As Object
Dim oVCurs As Object
Dim oTCurs As Object
oDoc = ThisComponent
oText = oDoc.Text
oVCurs = oDoc.CurrentController.getViewCursor()
oTCurs = oText.createTextCursorByRange(oVCurs.getStart())
' Create a row-set to query the database
RowSet = createUnoService("com.sun.star.sdb.RowSet")
RowSet.DataSourceName = "CostBenefitAnalysis"
RowSet.CommandType = com.sun.star.sdb.CommandType.COMMAND
RowSet.Command = "SELECT Name, Category, Description, Benefits, Costs FROM Summary"
RowSet.execute()
' loop through the resultset until no record is left
while RowSet.next()
WriteString( rowSet.getString(1), oText, oTCurs, TRUE, TRUE, FALSE )
WriteString( "[" + rowSet.getString(2) + "]", oText, oTCurs, TRUE, FALSE, FALSE )
Endl( oText, oTCurs )
WriteString( rowSet.getString(3), oText, oTCurs, FALSE, FALSE, TRUE )
Endl( oText, oTCurs )
if ( rowSet.getString(4) <> "" ) then
WriteString( "Benefits: ", oText, oTCurs, TRUE, FALSE, FALSE )
WriteString( rowSet.getString(4), oText, oTCurs, FALSE, FALSE, FALSE )
Endl( oText, oTCurs )
end if
if ( rowSet.getString(5) <> "" ) then
WriteString( "Costs: ", oText, oTCurs, TRUE, FALSE, FALSE )
WriteString( rowSet.getString(5), oText, oTCurs, FALSE, FALSE, FALSE )
Endl( oText, oTCurs )
end if
Endp( oText, oTCurs )
wend
End Sub
The subroutine, when invoked, connects to the database and renders the information into my Writer document just as I expect.