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 'OK' 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.
Here is the Word file i use
I can read the docx file, but i still don't know how to add some text to a table.
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 < IBodyElement > bodyElementIterator = xdoc.getBodyElementsIterator();
while (bodyElementIterator.hasNext()) {
IBodyElement element = bodyElementIterator.next();
if ("TABLE".equalsIgnoreCase(element.getElementType().name())) {
List < XWPFTable > 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();
}
}
}
