lotus-noteslotusscript

Lotusscript Rich Text Field adding Images or Unicode Characters to Rich Text Table


Is there any method of adding images or unicode characters from (say) Wingdings by in a table generated by lotusscript.

As the options for formatting of tables in lotusscript are limited I store a formatted table in a profile document and append it to the rich text field.

In the Queryopen event of the document I add the rtf table and add rows and populate. The one below is finding emails sent from a document and displaying them in that document in an RTF Any help is greatly appreciated.

Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)

    Dim session As New NotesSession
    Dim ws As New NotesUIWorkspace  
    Dim rtItem As NotesRichTextItem
    Dim rtnavBody As NotesRichTextNavigator
    Dim rtt As NotesRichTextTable
    Dim rc As Integer
    Dim cc As Integer 
    Dim rcc As Integer
    Dim cl As Integer
    Dim richStyle As NotesRichTextStyle
    Dim tablelayout As NotesRichTextItem 
    Dim db As NotesDatabase 
    Dim pdoc As NotesDocument
    
    On Error Goto errorsub
    
    Set uidoc = source
    Set db =session.CurrentDatabase
    Set doc = uidoc.Document
    
    Set view = db.Getview("MailByParentID")
    Set col = view.Getalldocumentsbykey(doc.DocID,True)

    
    If col.count=0 Then Exit Sub    'No items exist so no point in carrying on.
End If

Set rtItem = New NotesRichTextItem(doc,"rtfCustMail") 'field in the current document
Set pdoc=db.Getprofiledocument("Profile Doc")
Set tablelayout = pdoc.GetFirstItem("rtfMailLog") 'Get a ready made table from the Profile Doc.
Call rtitem.AppendRTItem(tablelayout)
Set rtnavBody = rtItem.CreateNavigator
Set richStyle = session.CreateRichTextStyle
Set idoc = col.Getfirstdocument()
            'Add a row to the table to hold the data for the first item in the order    
Call rtnavBody.FindFirstElement(RTELEM_TYPE_TABLE)
Set rtt = rtnavBody.GetElement  


Do Until idoc Is Nothing
    Call rtt.AddRow()
    
        'Write the item data into the tablecells -- 
    rc%= rtt.RowCount           'Find the number of rows in the table
    cc% =rtt.ColumnCount            
    rcc% =rc%*cc%               'Calculate total number of table cells
    cl% =rcc%-5             'Calculate cell number of the first cell in the new (last) row
    
    Call rtnavBody.FindNthElement(RTELEM_TYPE_TABLECELL,cl%)    'Move to the first cell in the last row 
    Call rtitem.BeginInsert(rtnavBody)
    Call rtitem.Appenddoclink(idoc,"")
    Call rtitem.EndInsert
    
    Call rtnavBody.FindNextElement(RTELEM_TYPE_TABLECELL)
    Call rtitem.BeginInsert(rtnavBody)
    Call rtitem.AppendText(******need to add characters in here or better still images.)
    Call rtitem.EndInsert
   'To      
    Call rtnavBody.FindNextElement(RTELEM_TYPE_TABLECELL)
    Call rtitem.BeginInsert(rtnavBody)
    Call rtitem.AppendText(idoc.SendTo(0))
    Call rtitem.EndInsert   
    
    etc etc.

    Set idoc = col.Getnextdocument(idoc)
Loop    

errorsub: Print " Line " Erl & " Reason - "& Error$ 

End Sub

Solution

  • Unicode characters can simply be appended as text. There is some complication because Notes is using LMBCS, not Unicode. Still, if you can paste the character you want into a text string in your LotusScript code, the conversions will be done behind the scenes. If there are any issues with it, I uploaded an NSF containing a full listing of all Unicode characters with their LMBCs equivalents on the OpenNTF website somewhere between 10 and 20 years ago. I still have a copy if it can no longer be found after the various changes to OpenNTF.

    BTW, a very useful trick that I've found for getting content into a NotesRichText item that is being constructed on the fly from parts that you have already built advance is the AppendToRTItem method. I.e., you are building rtitem, as above. You have a config document containing a rich text field containing the content that you want (e.g., an image, a hypertext link, something with a hide-when formula, etc.) so you open that config document, get the NotesRichText item from that document into rtitem2, and call rtitem2.AppendToRTItem(rtitem).