Я не могу понять, как вставить поля даты и времени в docx. Я полагаю, мне нужно использовать что-то вроде
run.getCTR().addNewFldChar().setFldCharType(STFldCharType.???)
но я не знаю как.
Bellow — это SSCCE, в котором insertCurrentXxxxField()
функции ведут себя не так, как нужно.
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class InsertCurrentDateAndTimeInDocxUsingApachePOI {
public static void main(String[] args) throws IOException {
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("Current date:");
insertCurrentDateField(run);
run.setText(" current time:");
insertCurrentTimeField(run);
FileOutputStream out = new FileOutputStream(new File("CurrentDateAndTime.docx"));
document.write(out);
}
private static void insertCurrentDateField(XWPFRun run){
run.setText("${here should be the current date field DD.MM.YY}");
}
private static void insertCurrentTimeField(XWPFRun run){
run.setText("${here should be the current time field HH:MM:SS}");
}
}
run.getCTR().addNewFldChar()
добавляет поле формы (FORMTEXT, FORMDROPDOWN, FORMCHECKBOX,...) - person Axel Richter   schedule 29.01.2016