在RTF域中添加Table

Developers sometimes need to retrieve cell values within a table in a Lotus Notes rich-text field (RTF). The following LotusScript code will display the values in each cell within the body of any Lotus Notes mail document.

GetElementCount is used to count different types of RichTextItems in a field. This example uses the Table type.

Sub Initialize
Dim ws As New NotesUIWorkspace
Dim s As New NotesSession
Dim db As NotesDatabase
Dim dc As NotesDocumentCollection
Dim maildoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim rtnav As NotesRichTextNavigator


Set db=s.CurrentDatabase
Set dc=db.UnprocessedDocuments

If dc.Count>1 Then
Msgbox "Please select a single document", MB_OK, 
"Travel HelpDesk"
Continue=False
End
 Else
Set maildoc=dc.GetFirstDocument()
Set rtitem=maildoc.GetFirstItem("Body")
Set rtnav=rtitem.CreateNavigator
count = GetElementCount(rtnav, RTELEM_TYPE_TABLE)
'msg$ = msg$ & "Tables:" & Chr(9)  & Chr(9) & count% & Chr(10)
'Messagebox msg$,, maildoc.Subject(0)
If count=0 Then
Messagebox "Body item does not contain a table,",, _
"Error"
Exit Sub
End If
 
For k=1 To count
If  rtnav.FindNthElement(RTELEM_TYPE_TABLE,k) Then
Dim rttab As NotesRichTextTable
Set rttab=rtnav.GetElement
Dim rtrange As NotesRichTextRange
Set rtrange=rtitem.CreateRange
If k=1 Then
Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)    
Else
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
End If
    
firstFlag = True
 
For i& = 1 To rttab.RowCount
For j& = 1 To rttab.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
End If
 Next
 End If
 
End Sub

Function GetElementCount(rtnav As NotesRichTextNavigator, 
eType As Integer) As Integer
 GetElementCount = 0
 If rtnav.FindFirstElement(eType) Then
  Do
GetElementCount = GetElementCount + 1
Loop While rtnav.FindNextElement()
 End If
End Function
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值