Manipulating RTF text fields with LS

Source: Internet
Author: User
All along, Lotus Notes Rich text fields are used very frequently, and in almost any Domino application, Rich text fields are used. The Lotus Notes Rich Text field is also powerful, and supports many types of images, tables, embedded objects, Http links, Notes links, attachments, and so on, in addition to supporting plain text. But there is a problem that has long plagued the lotusscript developers, and that is the flexibility of the various types of content in the Notes Rich text field is difficult, in fact, Domino in the process of continuous upgrading, has added many new LotusScript class to operate Notes Rich Text field, but many lotusscript developers are not familiar with this. This article describes how to use these classes to flexibly manipulate rich text fields.
Manipulating Notes Rich Text field-related LotusScript classes
The LotusScript classes related to manipulating Notes Rich text fields include:
Notesrichtextnavigator a Rich text field navigator to access various elements in a rich text field;
Notesrichtextrange represents a range of rich text field content, which can include multiple elements;
Notesrichtextdoclink represents a document link for rich text field content;
Notesembeddedobject represents an embedded object or file attachment;
Notesrichtextsection represents a section in a rich text field;
Notesrichtexttable represents a table in a rich text field;
Notesrichtextstyle represents various attributes of rich text;
Notesrichtextparagraphstyle represents the various attributes of a rich text paragraph;
Notescolorobject represents a color.

Below we use a program to analyze how each class is used.
First we create a blank NSF database, and then create a form called "Test_rtf", which has only one rich text field named "Body", and then creates a view in the default view named "Test" with the following code in the proxy. This program generates a document that contains a rich text field and generates various elements in the rich text field.
--------------------------------------------------
Sub Initialize ()
On Error GoTo A

Dim s as New notessession
Dim DB as NotesDatabase
Set db = S.currentdatabase
Dim Doc as NotesDocument
Set doc = New notesdocument (db)

Doc. Form = "Test_rtf"
Doc. DocID = doc. Universalid

Dim RTF as Notesrichtextitem
Set rtf = doc. Createrichtextitem ("Body")

' Generate a text paragraph and set its font size, color, and other properties
Dim style as Notesrichtextstyle
Set style = S.createrichtextstyle

Dim Pstyle as Notesrichtextparagraphstyle
Set Pstyle = S.createrichtextparagraphstyle

Dim Color as Notescolorobject
Set color = S.createcolorobject

Style. FontSize = 20
Style. Bold = True
Pstyle. Alignment = Align_left
Pstyle. Firstlineleftmargin = Ruler_one_inch

Call color. SETRGB (123, 234, 123)
Style. Notescolor = color. Notescolor
Call RTF. Appendstyle (Style)

Call RTF. Appendparagraphstyle (Pstyle)
Call RTF. AppendText ("This is a text paragraph, left-aligned. ")
Call RTF. Addnewline (1)

' Generate a database link linked to the current database
Call RTF. Appenddoclink (db, "linking to current Database", "Current Database")

' Generate a section that contains a table
Call RTF. Appendstyle (Style)
Call RTF. Beginsection ("This is a section", Style, color, True)
Call RTF. AppendText ("This is the beginning of the section")

Dim IRow as Integer
Dim Icol as Integer
irow% = 3
icol% = 3
Style. Notescolor = Color_blue
Call RTF. Appendstyle (Style)

' Add a 3x3 table
Call RTF. Appendtable (irow%, icol%)
Call RTF. AppendText ("This is the end of the sector")
Call RTF. Endsection

Dim nav as Notesrichtextnavigator
Set nav = rtf. CreateNavigator
Call NAV. Findfirstelement (Rtelem_type_tablecell)

Style. Fontsize=16
Style. Bold=false
Call RTF. Appendstyle (Style)

Dim I as Integer
Dim J as Integer
For i% = 1 to irow%
For j% = 1 to icol%
Call RTF. Begininsert (NAV)
Call RTF. AppendText (Rows & i% &, Columns & j%)
Call RTF. Endinsert
Call NAV. Findnextelement (Rtelem_type_tablecell)
Next
Next

' Add an attachment
Call RTF. Embedobject (Embed_attachment, "", "D:\aa1.png")
Call Doc. Save (True,true)


Exit Sub
A:
MsgBox "Error in Agent Agent_rtf" & Erl & "line, Description:---" & Error

End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.