Example: Working with tables in Java™ classes
- This agent displays the number of columns and rows for all the
tables in the Body item of the current document.
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(); } } }
- This agent finds the first table in the Body item of the current
document, finds all the cells in the table, and finds all the paragraphs
in each cell.
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(); } } }