Rich Text Alignment

I am trying to build a report within a NotesRichTextItem. The report will include text, which will beeither centered or left-justified, and tables with fixed width columns. To illustrate the setup,

I create a form called “Report” containing a single Rich Text field called “rtField”. Then run the

following agent:

Sub Initialize

Dim session As New NotesSession

Dim ws As New NotesUIWorkspace

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim rtLeft As NotesRichTextParagraphStyle

Dim rtCenter As NotesRichTextParagraphStyle

Dim tblstyle (1 To 2) As NotesRichTextParagraphStyle

Dim rtField As NotesRichTextItem

Dim nav As NotesRichTextNavigator

Dim table As NotesRichTextTable

Set db=session.CurrentDatabase

Set doc=db.CreateDocument()

Set rtLeft=session.CreateRichTextParagraphStyle

Set rtCenter=session.CreateRichTextParagraphStyle

Set tblstyle(1)=session.CreateRichTextParagraphStyle

Set tblstyle(2)=session.CreateRichTextParagraphStyle

rtLeft.Alignment=ALIGN_LEFT

rtCenter.Alignment=ALIGN_CENTER	

tblstyle(1).FirstLineLeftMargin=0

tblstyle(2).FirstLineLeftMargin=0

tblstyle(1).LeftMargin=0

tblstyle(2).LeftMargin=0

tblstyle(1).RightMargin=RULER_ONE_INCH * 2

tblstyle(2).RightMargin=RULER_ONE_INCH * 2

doc.form="Report"

Call doc.CreateRichTextItem("rtField")

Set rtField=doc.GetFirstItem("rtField")

Set nav=rtField.CreateNavigator



Call rtField.AppendParagraphStyle(rtCenter)

Call rtField.AppendText("This text should be centered.")

Call rtField.AddNewline(1)



Call rtField.AppendParagraphStyle(rtLeft)

Call rtField.AppendText("This text should be left justified.")

Call rtField.AddNewline(1)



Call rtfield.AppendTable(2,2,,,tblstyle)

Call nav.FindFirstElement(RTELEM_TYPE_TABLE)

Set table=nav.GetElement

Call nav.FindFirstElement(RTELEM_TYPE_TABLECELL)

rtfield.BeginInsert(nav)

Call rtfield.AppendText("1")

Call rtfield.EndInsert



Call nav.FindNextElement(RTELEM_TYPE_TABLECELL)

rtfield.BeginInsert(nav)

Call rtfield.AppendText("2")

Call rtfield.EndInsert



Call nav.FindNextElement(RTELEM_TYPE_TABLECELL)

rtfield.BeginInsert(nav)

Call rtfield.AppendText("3")

Call rtfield.EndInsert



Call nav.FindNextElement(RTELEM_TYPE_TABLECELL)

rtfield.BeginInsert(nav)

Call rtfield.AppendText("4")

Call rtfield.EndInsert



Call rtfield.AddNewline(1)

Call rtfield.AppendParagraphStyle(rtCenter)

Call rtField.AppendText("This text should be centered.")



Call rtField.AddNewline(1)

Call rtField.AppendParagraphStyle(rtLeft)

Call rtField.AppendText("This text should be left justified.")



Call rtField.AddNewline(1)

Call rtField.AppendParagraphStyle(rtCenter)

Call rtField.AppendText("This text should be centered.")



Call doc.Save(True,False)

Call ws.EditDocument(False,Doc)

End Sub

In the resulting document, text appearing before the table is correctly aligned, but

text after the table cannot be centered. If text following the table is placed in a second richtext field, it is formatted correctly, but this is not an option from a design standpoint, because it is not known until runtime how many tables will be in the report.

Subject: Found a solution

After finishing all operations on the table, delete the object references to the rich text field and its navigator, and then re-assign them:

Delete nav

Delete rtField

Set rtField=doc.GetFirstItem(“rtField”)

Set nav=rtField.CreateNavigator

This does not remove the rich text field from the document, but re-builds its representation in memory. After this is done, any text following the table is rendered with the correct formatting.

It appears that appending a table to the rich text field somehow interferes with the default styles of any text paragraphs following it.