title: How to add text to a specific position in the word file using Apache poi?
body: <p>I have a presence list that I need to change depending if the student is present or not. I need to look for student names and putt '<strong>OK</strong>' if the student is present and ' / ' if the student is absent. So I wonder how to search for text in the doc file and how to put text in a particular position. </p>
  
  <p>Here is the Word file i use</p>
  
  <p><a href="https://i.stack.imgur.com/taASI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/taASI.png" alt="Here is the Word file i use"></a></p>
  
  <p>I can read the docx file, but i still don't know how to add some text to a table.</p>
  
  <pre><code>public class WordFile {
      public static void main(String[] args) {
          try {
  
              String FilePath = System.getProperty("user.home") + "\\Desktop\\Admin dokument\\EM.docx";
              FileInputStream fis = new FileInputStream(FilePath);
              XWPFDocument xdoc = new XWPFDocument(OPCPackage.open(fis));
              Iterator &lt; IBodyElement &gt; bodyElementIterator = xdoc.getBodyElementsIterator();
  
              while (bodyElementIterator.hasNext()) {
                  IBodyElement element = bodyElementIterator.next();
  
                  if ("TABLE".equalsIgnoreCase(element.getElementType().name())) {
                      List &lt; XWPFTable &gt; tableList = element.getBody().getTables();
                      for (XWPFTable table: tableList) {
                          System.out.println("Total Number of Rows of Table:" + table.getNumberOfRows());
                          System.out.println(table.getText());
                      }
                  }
              }
          } catch (Exception ex) {
              ex.printStackTrace();
          }
      }
  }
  </code></pre>