Examples: appendTable method

  1. This agent creates a basic table in a rich text item.
    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
    
      public void NotesMain() {
    
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
    
          // (Your code goes here) 
          Database db = agentContext.getCurrentDatabase();
          Document doc = db.createDocument();
          doc.appendItemValue("Form", "MainTopic");
          doc.appendItemValue("Subject", "Basic table");
          RichTextItem rti = doc.createRichTextItem("Body");
          rti.appendText("Paragraph of text.");
          rti.addNewLine(2);
          // Create table with 4 rows and 3 columns
          rti.appendTable(4, 3);
          doc.save(true, true);
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. This agent creates a tabbed table in a rich text item.
    import lotus.domino.*;
    import java.util.Vector;
    
    public class JavaAgent extends AgentBase {
    
      public void NotesMain() {
    
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
    
          // (Your code goes here) 
          Database db = agentContext.getCurrentDatabase();
          Document doc = db.createDocument();
          doc.appendItemValue("Form", "MainTopic");
          doc.appendItemValue("Subject", "Tabbed table");
          RichTextItem rti = doc.createRichTextItem("Body");
          rti.appendText("Paragraph of text.");
          rti.addNewLine(2);
          // Create tabbed table with 4 rows and 3 columns
          Vector tabs = new Vector();
          for (int i = 0; i < 4; i++) {
            String element = "Row " + (i + 1);
            tabs.addElement(element);
          }
          rti.appendTable(4, 3, tabs);
          doc.save(true, true);
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
  3. This agent creates a basic table and populates it.
    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
    
      public void NotesMain() {
    
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
    
          // (Your code goes here) 
          Database db = agentContext.getCurrentDatabase();
          Document doc = db.createDocument();
          doc.appendItemValue("Form", "MainTopic");
          doc.appendItemValue("Subject", "Basic table populated");
          RichTextItem rti = doc.createRichTextItem("Body");
          rti.appendText("Paragraph of text.");
          rti.addNewLine(2);
          // Create table with 4 rows and 3 columns
          rti.appendTable(4, 3);
          // Populate table
          RichTextNavigator rtnav = rti.createNavigator();
          rtnav.findFirstElement(RichTextItem.RTELEM_TYPE_TABLECELL);
          for (int irow = 1; irow < 5; irow++) {
            for (int icol = 1; icol < 4; icol++) {
              rti.beginInsert(rtnav);
              rti.appendText("Row " + irow + ", column " + icol);
              rti.endInsert();
              rtnav.findNextElement(RichTextItem.RTELEM_TYPE_TABLECELL);
            }
          }
          doc.save(true, true);
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  4. This agent creates a basic auto-width table with a left margin of 1.5 inches rather than the default 1 inch, and populates it.
    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
    
      public void NotesMain() {
    
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
    
          // (Your code goes here) 
          Database db = agentContext.getCurrentDatabase();
          Document doc = db.createDocument();
          doc.appendItemValue("Form", "MainTopic");
          doc.appendItemValue("Subject",
            "Basic table with 1.5 left margin");
          RichTextItem rti = doc.createRichTextItem("Body");
          rti.appendText("Paragraph of text.");
          rti.addNewLine(2);
          // Create table with 4 rows and 3 columns
          rti.appendTable(4, 3, null,
            (int)(RichTextParagraphStyle.RULER_ONE_INCH * 1.5), null);
          // Populate table
          RichTextNavigator rtnav = rti.createNavigator();
          rtnav.findFirstElement(RichTextItem.RTELEM_TYPE_TABLECELL);
          for (int irow = 1; irow < 5; irow++) {
            for (int icol = 1; icol < 4; icol++) {
              rti.beginInsert(rtnav);
              rti.appendText("Row " + irow + ", column " + icol);
              rti.endInsert();
              rtnav.findNextElement(RichTextItem.RTELEM_TYPE_TABLECELL);
            }
          }
          doc.save(true, true);
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  5. This agent creates a basic table and populates it. The width of each column is fixed at 1.5 inches. The left margin of the table is 1.5 inches.
    import lotus.domino.*;
    import java.util.Vector;
    
    public class JavaAgent extends AgentBase {
    
      public void NotesMain() {
    
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
    
          // (Your code goes here) 
          Database db = agentContext.getCurrentDatabase();
          Document doc = db.createDocument();
          doc.appendItemValue("Form", "MainTopic");
          doc.appendItemValue("Subject",
            "Basic table with 1.5 left margin");
          RichTextItem rti = doc.createRichTextItem("Body");
          rti.appendText("Paragraph of text.");
          rti.addNewLine(2);
          // Create table with 4 rows and 3 columns
          RichTextParagraphStyle rtps =
            session.createRichTextParagraphStyle();
          rtps.setLeftMargin(0);
          rtps.setFirstLineLeftMargin(0);
          rtps.setRightMargin(
            (int)(RichTextParagraphStyle.RULER_ONE_INCH * 1.5));
          Vector styles = new Vector();
          for (int i = 0; i < 3; i++) {
            styles.addElement(rtps);
          }
          rti.appendTable(4, 3, null,
            (int)(RichTextParagraphStyle.RULER_ONE_INCH * 1.5), styles);
          // Populate table
          RichTextNavigator rtnav = rti.createNavigator();
          rtnav.findFirstElement(RichTextItem.RTELEM_TYPE_TABLECELL);
          for (int irow = 1; irow < 5; irow++) {
            for (int icol = 1; icol < 4; icol++) {
              rti.beginInsert(rtnav);
              rti.appendText("Row " + irow + ", column " + icol);
              rti.endInsert();
              rtnav.findNextElement(RichTextItem.RTELEM_TYPE_TABLECELL);
            }
          }
          doc.save(true, true);
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }