Home > Domino Tips > Developer > LotusScript > Table in a rich text field
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

LOTUSSCRIPT

Table in a rich text field


Ben Connery
03.15.2005
Rating: -3.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


This code is designed to create a non-tabbed table of two rows and five columns in a rich text field to display information. I've added in static text but it could be used to display information from a document as well.

I've implemented this as an agent, as the code this came from was used in this way, but it could be a button, query open etc. You can use the same classes to create a tabbed table, but this tip doesn't do that. This code works with R6 and above only.

  
  Code: Sub Initialize
 Dim sess As New NotesSession
 Dim ws As New NotesUIWorkspace
 Dim dbCurr As NotesDatabase
 Dim docProcess As NotesDocument
 Dim dcProcess As NotesDocumentCollection
 
 Dim rtiItem As NotesRichTextItem
 
 Dim rtnav As NotesRichTextNavigator
 Dim rtt As NotesRichTextTable
 Dim rtsTableHeader As NotesRichTextStyle
 Dim rtsTableRow As NotesRichTextStyle
 
 Dim sData(4) As String
 Dim sHeaders(4) As String
 Dim sPrefix As String
 Dim iCtr As Integer
 Dim iRow As Integer
 Dim iCol As Integer
 
 'We declare an array of paragraph 
styles to pass in when creating the 
table
 Dim rtpsCols(4) As 
NotesRichTextParagraphStyle
 
 Set dbCurr = sess.CurrentDatabase
 Set dcProcess = 
dbCurr.UnprocessedDocuments
 
 If dcProcess.Count > 0 Then
  
  'These are display headers for the table
  sHeaders(0) = "Header 1"
  sHeaders(1) = "Header 2"
  sHeaders(2) = "Header 3"
  sHeaders(3) = "Header 4"
  sHeaders(4) = "Header 5"
  'An array of data for the Columns
  sData(0) = "Col 1"
  sData(1) = "Col 2"
  sData(2) = "Col 3"
  sData(3) = "Col 4"
  sData(4) = "Col 5"
  
  'Set up the text styles we want to 
use for displaying the text
  Set rtsTableHeader = 
sess.CreateRichTextStyle
  rtsTableHeader.FontSize = 10 
  rtsTableHeader.Bold = True
  Set rtsTableRow= 
sess.CreateRichTextStyle
  rtsTableRow.FontSize = 8
  rtsTableRow.Bold = False
  
  'Set up the paragraph styles for the table
  'The column widths are set 
by setting the left margin to 0 then 
the right margin to 
  'what the column width should be
  Set rtpsCols(0) = 
sess.CreateRichTextParagraphStyle
  'This column in left aligned
  rtpsCols(0).Alignment = 0
  rtpsCols(0).Firstlineleftmargin = 0
  rtpsCols(0).Leftmargin = 0
  rtpsCols(0).RightMargin = 
RULER_ONE_CENTIMETER * 7.51
  
  'This column is centre aligned
  Set rtpsCols(1) = 
sess.CreateRichTextParagraphStyle
  rtpsCols(1).Alignment =3
  rtpsCols(1).Firstlineleftmargin = 0
  rtpsCols(1).Leftmargin = 0
  rtpsCols(1).RightMargin = 
RULER_ONE_CENTIMETER * 1.43  
  Set rtpsCols(2) = 
sess.CreateRichTextParagraphStyle
  rtpsCols(2).Alignment =3  
  rtpsCols(2).Firstlineleftmargin = 0
  rtpsCols(2).Leftmargin = 0
  rtpsCols(2).RightMargin = 
RULER_ONE_CENTIMETER * 2.18  
  Set rtpsCols(3) = 
sess.CreateRichTextParagraphStyle
  rtpsCols(3).Alignment =3
  rtpsCols(3).Firstlineleftmargin = 0
  rtpsCols(3).Leftmargin = 0
  rtpsCols(3).RightMargin = 
RULER_ONE_CENTIMETER * 1.68
  
  Set rtpsCols(4) = 
sess.CreateRichTextParagraphStyle
  rtpsCols(4).Alignment =0
  rtpsCols(4).Firstlineleftmargin = 0
  rtpsCols(4).Leftmargin = 0
  rtpsCols(4).RightMargin =
 RULER_ONE_CENTIMETER * 10.73
  
  Set docProcess = dcProcess.GetFirstDocument
  While Not docProcess Is Nothing
   
   'I've used good old Body as my rich text field
   Set rtiItem = docProcess.GetFirstItem("Body")
   'The styles only have about three fonts that can be 
used by default
   'Arial isn't one of them so we have to 'Get' it from 
the rich text item
   'I don't really understand this but that's how it 
works...
   rtsTableHeader.NotesFont = rtiItem.GetNotesFont
("Arial", True)
   rtsTableRow.NotesFont = rtiItem.GetNotesFont("Arial", 
True)
   
   'We create the table, with 1 row, 5 columns, "" for the 
title, so it's not a tabbed table
   '1440 is the margin in twips, which is an inch, or 
2.54*567(which is a cm in twips)
   'rtpsCols is the array of rich text paragraph styles we 
set up earlier
   Call rtiItem.AppendTable(1,5,"",1440, rtpsCols)
   Call docProcess.Save(True,False)
   
   'In order to get the table elements we have to use a 
couple of methods
   'One is to get the table as a rich text table element
   'The other is just to get navigate to the columns so we 
can insert text
   
   'This element enables us to navigate through the rich 
text field
   Set rtnav = rtiItem.CreateNavigator
   
   'Get the table as a rich text table element so we can 
add rows
   Set rtt = rtnav.GetFirstElement(RTELEM_TYPE_TABLE)
   
   'Once you set a style the rich text field has that 
style until we say otherwise
   Call rtiItem.AppendStyle(rtsTableHeader)
   
   'This navigates us to the first table cell
   Call rtnav.FindFirstElement
(RTELEM_TYPE_TABLECELL) 
   For iCol = 1 To 5 Step 1
    'Add in our text then get the next cell
    Call rtiItem.BeginInsert(rtnav)
    Call rtiItem.AppendText(sHeaders(iCol-1))
    Call rtiItem.EndInsert
    Call rtnav.FindNextElement
(RTELEM_TYPE_TABLECELL)
   Next
   'Now we change the style to our row style
   Call rtiItem.AppendStyle(rtsTableRow)
   'Add a row, then go to the first cell in that row, 
which will be the next cell
   Call rtt.AddRow
   Call rtnav.FindNextElement
(RTELEM_TYPE_TABLECELL)
   For iCtr=0 To 4
    'Add in our text then get the next cell
    Call rtiItem.BeginInsert(rtnav)
    Call rtiItem.AppendText(sData(iCtr))
    Call rtiItem.EndInsert
    Call rtnav.FindNextElement
(RTELEM_TYPE_TABLECELL)
   Next
   Call rtt.AddRow
   Call rtnav.FindNextElement
(RTELEM_TYPE_TABLECELL)
   For iCtr=0 To 4
    Call rtiItem.BeginInsert(rtnav)
    Call rtiItem.AppendText(sData(iCtr))
    Call rtiItem.EndInsert
    Call rtnav.FindNextElement
(RTELEM_TYPE_TABLECELL)
   Next
   
   Call docProcess.Save(True,False)
   Set docProcess = 
dcProcess.GetNextDocument(docProcess)
  Wend
 End If
 
End Sub

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Ben Connery. Please let others know how useful it is via the rating scale belowip. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
LotusScript
Alternate version of @Command forwards subform via LotusScript
Process large arrays in Notes forms without undue coding or testing
How to use LotusScript to modify a Lotus Notes view selection
Display a custom message box using a LotusScript-generated button
Debug Lotus Notes documents using extracted data
Extracting attachments from a Lotus Notes rich-text field
Programmatically replace the design of Lotus Notes databases
Reading a binary field in an Oracle database with LotusScript
LotusScript equivalent of @Picklist for Lotus Notes
Launch large attachments within an email from a Notes database

LotusScript
Alternate version of @Command forwards subform via LotusScript
Process large arrays in Notes forms without undue coding or testing
How to use LotusScript to modify a Lotus Notes view selection
Display a custom message box using a LotusScript-generated button
Can I use LotusScript to merge cells in a Microsoft Word table?
Debug Lotus Notes documents using extracted data
Extracting attachments from a Lotus Notes rich-text field
Programmatically replace the design of Lotus Notes databases
Reading a binary field in an Oracle database with LotusScript
LotusScript equivalent of @Picklist for Lotus Notes

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.

HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 1999 - 2008, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts