Gerard Cruz
Gerard Cruz

Reputation: 649

How to read cell values from a single table inside a richtext field using lotusscript?

Scenario is that there's a form with a RichText field (let's say it's called Body); as well as a button called Read

Upon creation of document, the RichText field body will have a default 2x2 table inside of it. The user will have to input values in the cells and press read which will read the values from the table and insert it into an array.

Upvotes: 0

Views: 1593

Answers (1)

Tode
Tode

Reputation: 12060

The document has to be saved in order to be able to read the richtext- item- contents.

Then the NotesRichtextTable- Class is your point to start with. The follwoing example is mostly taken from the designer- help (yes, the one that is integrated in your designer, but also found here at IBM...)

Dim ws as New NotesUIWorkspace
Dim uidoc as NotesUIDocument

Dim doc as NotesDocument
Dim rti As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator
Dim rtt As NotesRichTextTable
Dim rtrange As NotesRichTextRange

Set uidoc = ws.CurrentDocument
Call uidoc.Save() 'otherwise you will not be able to get the contents of the richtextitem

Set doc = uidoc.document
Set rti = doc.GetFirstItem("Body")
Set rtnav = rti.CreateNavigator
If Not rtnav.FindFirstElement(RTELEM_TYPE_TABLE) Then
  Messagebox "Body item does not contain a table,",, _
  "Error"
  Exit Sub
End If
Set rtt = rtnav.GetElement
Set rtrange = rti.CreateRange
Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
firstFlag = True
For i& = 1 To rtt.RowCount
  For j& = 1 To rtt.ColumnCount
    If Not firstFlag Then
      Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
    Else
      firstFlag = False
    End If
    Call rtrange.SetBegin(rtnav)
    Messagebox rtrange.TextParagraph,, _
    "Row " & i& & _
    ", Column " & j&
  Next
Next

Upvotes: 3

Related Questions