P
PavelT100
Код:
Dim session As New NotesSession
Dim rtitem As NotesRichTextItem
Set rtitem=doc.GetFirstItem("Body")
Dim richStyle As NotesRichTextStyle
Set richStyle = session.CreateRichTextStyle
richStyle.FontSize = 9
richStyle.Underline = False
richStyle.Bold=True
richStyle.NotesColor=COLOR_DARK_BLUE
Dim begIns As Boolean
begIns=BeginBodyInsert(rtItem)
If Not ( rtItem Is Nothing ) Then
Dim colorObject As NotesColorObject
Set colorObject = session.CreateColorObject
colorObject.NotesColor = COLOR_BLUE
Call rtitem.BeginSection(Format$(Now, "dd/mm/yy hh:nn") & " commente par " & session.CommonUserName, richStyle, colorObject, True)
richStyle.Bold=False
richStyle.NotesColor = COLOR_BLACK
Call rtitem.AppendStyle(richStyle)
Call rtitem.AppendText( " " )
Call rtitem.AppendText( "Нужный текст" )
Call rtitem.AddNewLine( 1 )
Call rtitem.EndSection
If begIns Then
rtitem.EndInsert
End if
Call doc.Save(False, False )
End If
.....
Function BeginBodyInsert( rtItem As NotesRichTextItem ) As Boolean
Dim rtnav As NotesRichTextNavigator
Dim rtRange As NotesRichTextRange
Dim firstSection As Boolean
firstSection = False
BeginBodyInsert=False
If Not ( rtitem Is Nothing ) Then
If rtitem.ValueLength > 0 Then
Set rtnav = rtitem.createNavigator()
If rtnav.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH) Then
BeginBodyInsert=True
ElseIf rtnav.FindFirstElement(RTELEM_TYPE_SECTION) Then
BeginBodyInsert=True
firstSection = True
ElseIf rtnav.FindFirstElement(RTELEM_TYPE_TEXTRUN) Then
BeginBodyInsert=True
End If
If Not( BeginBodyInsert ) Then
MessageBox "Can't find where first paragraph starts"
Exit Function
End If
End If
Set rtRange = rtItem.CreateRange
Call rtRange.SetBegin(rtNav)
If Not FirstSection Then
Call rtnav.SetCharOffset(1)
Call rtRange.SetEnd(rtNav)
End If
rtNav.Setposition(rtRange)
If BeginBodyInsert Then
Call rtitem.BeginInsert(rtnav,False)
End If
End If
End Function
Есть такой код, но он очень проблемный. Если, например, в документе есть секции в начале, а потом идёт текст, то в таком случае моя секция добавится перед текстом, но не перед секциями, то есть не в начало документа.