It is possible to automate the creation of MS Word documents and also to style the text. For this a Word document is created or opened via the Xbase++ COM/ActiveX layer. The Word instance is represented in Xbase++ by an object of the class AutomationObject(). The document can be manipulated via the interfaces provided by Word. A documentation of the interfaces is provided by Microsoft: https://docs.microsoft.com/en-us/dotnet/api/microsoft.office.interop.word?view=word-pia

The creation of a Word document is very simple in Xbase++:

Xbase++:
// Create and show a new Word instance
oWord := CreateObject("Word.Application")
IF Empty( oWord )
   MsgBox( "Microsoft Word is not installed" )
ENDIF

oWord:visible := .T.

// Add a new document
oWord:Documents:add()

Now it is handy to know that the Macro Recorder of Word can be used to create a VB Script which documents the necessary operations to achieve the desired result. You start the Macro Recorder in the Word application via View->Macros. In the following example we set the font to "Bold" and "Underline". Then we type the text "Hello World!". Now the Macro Recorder can be stopped and the macro can be viewed via the "Edit" button:

Code:
Sub Macro2()
'
' Macro2 Macro
'
'
    Selection.Font.Bold = wdToggle
    Selection.Font.UnderlineColor = wdColorAutomatic
    Selection.Font.Underline = wdUnderlineSingle
    Selection.TypeText Text:="Hello World!"
End Sub

We see VB Script source code whose syntax is very similar to that of Xbase++. In particular we can see:
  • The send operator is a simple dot
  • The assignment operator is "="
  • Function arguments are passed without enclosing round brackets
  • Arguments are passed by their names (named parameters)
The equivalent Xbase++ code then looks like this:

Xbase++:
// Send operator is ":", assignment with ":="
oWord:Selection:Font:Bold := wdToggle
oWord:Selection:Font:UnderlineColor := wdColorAutomatic
oWord:Selection:Font:Underline := wdUnderlineSingle
// Method call with "(" and ")". No parameter name "Text"
oWord:Selection:TypeText( "Hello World!" )

Now the code is not compilable yet, because constants are used which Xbase++ does not know. However, Xbase++ is installed with a command line tool which can be used to create a suitable header file. In this example the output is redirected to the file word.ch, which can then be included in the prg source code using the preprocessor directive #include:

Code:
tlb2ch.exe application.word > word.ch

Note: Just as an MS Word document was created and manipulated here, it is possible to control MS Excel and the other MS Office tools via the automation technology.

An introduction to the automation technology and the required functions and classes can be found in the Xbase++ documentation:

Overview
CreateObject()
AutomationObject()