例: Java™ クラスで表を処理する

  1. 次のエージェントは、現在の文書の Body アイテムに含まれる、すべての表の列数と行数を表示します。
    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)) {
            int count = 0;
            do {
              count++;
              RichTextTable rttable = (RichTextTable)rtnav.getElement();
              System.out.println("Table " + count);
              System.out.println(
                "¥tColumn count = " + rttable.getColumnCount());
              System.out.println(
                "¥tRow count = " + rttable.getRowCount());
            } while (rtnav.findNextElement());
          }
          else
            System.out.println("Body does not contain any tables");
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }
  2. 次のエージェントは、現在の文書の Body アイテム内の最初の表、その表のすべてのセル、各セルのすべての段落を順に検索します
    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)) {
            // Set up range and navigator for table
            RichTextRange rtrange = body.createRange();
            rtrange.setBegin(rtnav);
            rtrange.setEnd(rtnav);
            RichTextNavigator rtnav2 = rtrange.getNavigator();
            // Find cells in table
            RichTextRange rtrange2 = body.createRange();
            RichTextRange rtrange3 = body.createRange();
            int counter = 0;
            rtnav2.findFirstElement(RichTextItem.RTELEM_TYPE_TABLECELL);
            do {
              counter++;
              System.out.println("Cell " + counter);
              // Set up range and navigator for cell
              rtrange2.setBegin(rtnav2);
              rtrange2.setEnd(rtnav2);
              RichTextNavigator rtnav3 = rtrange2.getNavigator();
              // Find paragraphs in cell
              if (rtnav3.findFirstElement(
              RichTextItem.RTELEM_TYPE_TEXTPARAGRAPH)) {
                do {
                  rtrange3.setBegin(rtnav3);
                  rtrange3.setEnd(rtnav3);
                  System.out.println(rtrange3.getTextParagraph());
                } while (rtnav3.findNextElement());
              }
                else System.out.println("¥tNo text in cell.");
            } while (rtnav2.findNextElement());
          }
          else
            System.out.println("Body does not contain any tables");
    
        } catch(Exception e) {
          e.printStackTrace();
        }
      }
    }