Notes Domino 6 New Feature - Creating a Table via LotusScript Click here to see all the Developer/Admin Tips

Date tip published:03/10/2003
Description:Notes Domino 6 allows you to create a table programmatically using LotusScript. Once the table is created the contents of each cell can be modified or appended to. This tip includes a database which can be downloaded to demonstrate the code explanation.


To learn more about the many new enhancements to Release 6, how to get re-certified as a Release 6 CLP, and train your users on this new release use the following links:

Notes Domino 6 Application Development Update
Notes Domino 6 Application Development 1
Beginner LotusScript for Notes Domino 6
Intermediate LotusScript for Notes and Domino 6




This tip was taken from TLCC's highly acclaimed Notes Domino 6 Application Development Update course.

This comprehensive course will make you a Release 6 expert in a mere 2 1/2 days. Easy, convenient and cost-effective, it will thoroughly prepare you for the Notes Domino 6 Application Development Update Exam required to achieve Notes Domino 6 CLP status.

Forget stiff or boring simulations. Along with clearly showing how to use the new Notes Domino 6 development features, TLCC's Notes Domino 6 Application Development Update course offers extensive activities and demonstrations done right in Domino Designer.

You will learn to lock documents and design elements, debug code on a remote server, and save disk space with single copy templates. Get hands-on experience using the new design elements like layers, style sheets, HTML files, JavaScript libraries, and more. Learn how to enable the new in-view document editing feature and the embedded editor feature. Learn and use the many new and enhanced @functions and @commands. Program the new LotusScript/Java objects to work with rich text elements like tables, sections and doclinks. Connect to relational databases using Data Connection Resources, plus much more! As always, you can learn at your own pace, at your own place with TLCC.

TLCC's Notes Domino 6 Application Development Update course - it’s the ideal way to learn Release 6, prepare for the update exam, and quickly become certified as a Notes Domino 6 CLP.

Click here to see customer comments on this course!


Click here for more information on TLCC's Notes Domino 6 Application Development Update course.




You can download a Notes database containing a demonstration of this tip by clicking the icon below. This demonstration database includes this full technical explanation plus the demonstration example. Notes 6 is required to run this demonstration.


r6table.nsf

Creating a Table via LotusScript




To create a table, use the new AppendTable method of the NotesRichTextItem class. Specify the number of rows and columns for the new table in the first two arguments of the AppendTable method. There are optional arguments to specify the tab labels, the left margin for the table and the paragraph style for the text in the columns.

The AppendTable method can be used to create two types of tables:

  • AppendTable creates a Basic table when tab labels are NOT specified
  • AppendTable creates a Tabbed table when tab labels are specified

    These labels are specified in the third parameter as a String array which is the same size as the number of rows in the table. This parameter is optional as noted above.

    The fourth parameter is the left margin of the table. See the Domino Designer Help below to see how the margin is specified. The parameter is optional.

    The final parameter controls the style of the table cell including the width of the cells. This parameter is also optional and, if not specified, will create a auto-width table. This parameter is an array of NotesRichTextParagraphStyle Objects, one for each column in the table. The left margins control where the text starts in the cell and the right margin controls the width of the cell. See the example below to see how this parameter is used.

    From Lotus Domino Designer 6 Help


    AppendTable method
    Inserts a table in a rich text item. The table text takes the current style of the item.
    Note This method is new with Release 6.

    Defined in
    NotesRichTextItem

    Syntax
    Call notesRichTextItem.AppendTable( rows%, columns% [, labels] [, leftMargin&] [, rtpsStyleArray] )

    Parameters
    rows%
      Integer. Number of rows in the table.
    columns%
      Integer. Number of columns in the table.
    labels
      Array of type String. Optional. Text of labels for a tabbed table. The number of array elements must equal the number of rows. Omitting this parameter appends a basic table. Including this parameter appends a tabbed table.
    leftMargin&
      Long. Optional. Left margin of the table in twips. Defaults to 1440. The following constants are available:
      • RULER_ONE_CENTIMETER (567)
      • RULER_ONE_INCH (1440)
    rtpsStyleArray
      Array of type NotesRichTextParagraphStyle. Optional. Creates a table with fixed-width columns and style attributes as specified. Omitting this parameter creates an auto-width table. The array must contain one element for each column in the table in sequence. Explicitly set the first line left margin and left margin, which control the start of text relative to the start of the column, and the right margin, which controls column width.

    Usage
      By default the insertion occurs at the end of the item. You can change the insertion point with BeginInsert and EndInsert.
      The NotesRichTextTable class represents a table.


    Technique: Append Basic Table


    Here is a description of the code for the [Append Basic Table] button in this demonstration.

    1. The first set of statements declare and set variables for the current workspace, the front-end document and the back-end document.

    1.Sub Click(Source As Button)
    2. Dim uiw As New NotesUIWorkspace
    3. Dim uidoc As NotesUIDocument
    4. Set uidoc = uiw.CurrentDocument
    5. Dim doc As NotesDocument
    6. Set doc = uidoc.Document

      2. This set of statements creates the arrstyle array. Two RichTextParagraphStyle objects are added to this array. The first column is set to a width of two inches on line 12 and the second column is set to a width of three inches on line 17.

      7. Dim session As New NotesSession
      8. Dim arrstyle(1 To 2) As NotesRichTextParagraphStyle
      9. Dim col As Integer
      10. col = 1
      11. Set arrstyle(col) = session.CreateRichTextParagraphStyle
      12. arrstyle(col).rightmargin = ruler_one_inch * 2
      13. arrstyle (col).leftmargin = 100
      14. arrstyle(col).firstlineleftmargin = 100
      15. col = 2
      16. Set arrstyle(col) = session.CreateRichTextParagraphStyle
      17. arrstyle(col).rightmargin = ruler_one_inch * 3
      18. arrstyle(col).leftmargin = 100
      19. arrstyle(col).firstlineleftmargin = 100

        3. The body variable is created and set to the first Body field in the document. In Line 26, the AppendTable method of the NotesRichTextItem class is used to append a table to the end of the Body field. Arguments in the AppendTable method specify 5 rows, 2 columns, no labels, no left margin and the arrsytle array of paragraph styles for the columns. Since no labels are passed, a basic-type table is created.

        20. Dim body As NotesRichTextItem
        21. Set body = doc.GetFirstItem("Body")
        22. If body Is Nothing Then
        23. Set body = doc.CreateRichTextItem("Body")
        24. End If
        25.
        26. Call body.AppendTable(5,2, , , ArrStyle)

          4. The next set of statements add content to the table cells in the new table. The rtnav variable is declared as a NotesRichTextNavigator object and set to the Body field in the document. In Line 30, rttable is set to the last table in the Body field (the one that was created in Line 26). The number of rows for the table is returned in Line 35 and the number of columns for the table is returned in Line 36. The total number of cells in the table is calculated in Line 37. A For loop, which begins on Line 38, is used to access and add content to the next table cell. Looping continues until content is added to all table cells.

          27. Dim rtnav As NotesRichTextNavigator
          28. Set rtnav = body.CreateNavigator
          29. Dim rttable As NotesRichTextTable
          30. Set rttable = rtnav.GetLastElement(RTELEM_TYPE_TABLE)
          31. Dim rows As Integer, cols As Integer, total As Integer
          32. If rttable Is Nothing Then
          33. Msgbox "No table created"
          34. Else
          35. rows = rttable.RowCount
          36. cols = rttable.ColumnCount
          37. total = rows * cols
          38. For i = 1 To total
          39. Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
          40. Call body.BeginInsert(rtNav)
          41. Call body.AppendText("This is in cell number " &i)
          42. Call body.EndInsert()
          43. Next i
          44. End If

            5. The current document is saved, closed and reopened to display the change.

            45. doc.save True, True
            46. uidoc.Close
            47. Call uiw.EditDocument(False,doc)
            48.End Sub