例: RichTextTable class

  1. 次のエージェントは、文書を作成し、文書内のリッチテキストアイテム内に基本的な表を作成した後、表のプロパティを表示して表に入力します。
    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();
          // Create document with Body item
          Document doc = db.createDocument();
          doc.appendItemValue("Form", "MainTopic");
          doc.appendItemValue("Subject", "Table 4 x 3");
          RichTextItem body = doc.createRichTextItem("Body");
          // Create table in body item
          int rowCount = 4;
          int columnCount = 3;
          body.appendTable(rowCount, columnCount);
          // Print table properties
          RichTextNavigator rtnav = body.createNavigator();
          RichTextTable rttable = (RichTextTable)rtnav.getFirstElement(
            RichTextItem.RTELEM_TYPE_TABLE);
          System.out.println("Table properties:");
          System.out.println("¥tRows = " + rttable.getRowCount());
          System.out.println("¥tColumns = " + rttable.getColumnCount());
          System.out.println("¥tCStyle = " + rttable.getStyle());
          System.out.println("¥tColor = " + rttable.getColor().getNotesColor());
          System.out.println("¥tColor = " + rttable.getAlternateColor().getNotesColor());
          // Populate table
          rtnav.findFirstElement(RichTextItem.RTELEM_TYPE_TABLECELL);
          for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 3; j++) {
              body.beginInsert(rtnav);
              body.appendText("Row " + (i + 1) + ", column " + (j + 1));
              body.endInsert();
              rtnav.findNextElement();
            }
          }
          // Save document
          doc.save(true, true);
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. 次のエージェントは、アイテム内の最初の表のセルを取得し、各セルの最初のテキスト段落を表示します。
    import lotus.domino.*;
    
    public class JavaAgent extends AgentBase {
    
      public void NotesMain() {
    
        try {
          Session session = getSession();
          AgentContext agentContext = session.getAgentContext();
    
          // (Your code goes here) 
          DocumentCollection dc = agentContext.getUnprocessedDocuments();
          Document doc = dc.getFirstDocument();
          RichTextItem body = (RichTextItem)doc.getFirstItem("Body");
          RichTextNavigator rtnav = body.createNavigator();
          if (rtnav.findFirstElement(RichTextItem.RTELEM_TYPE_TABLE)) {
            RichTextRange rtrange = body.createRange();
            rtrange.setBegin(rtnav);
            rtrange.setEnd(rtnav);
            RichTextNavigator rtnav2 = rtrange.getNavigator();
            RichTextRange rtrange2 = body.createRange();
            rtnav2.findFirstElement(RichTextItem.RTELEM_TYPE_TABLECELL);
            do {
              rtrange2.setBegin(rtnav2);
              System.out.println(rtrange2.getTextParagraph());
            } while (rtnav2.findNextElement());
          }
          else
            System.out.println("Body contains no tables");
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }