--- src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java (revision 1151345)
+++ src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java (working copy)
@@ -30,6 +30,7 @@
import org.apache.poi.openxml4j.opc.PackageRelationship;
import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocProtect;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSettings;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTZoom;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STDocProtect;
@@ -147,6 +148,24 @@
safeGetDocumentProtection().setEnforcement(STOnOff.X_0);
}
+ /**
+ * Enforces fields update on document open (in Word).
+ * In the settings.xml file
+ * sets the updateSettings value to true (w:updateSettings w:val="true")
+ *
+ * NOTICES:
+ *
+ * - Causing Word to ask on open: "This document contains fields that may refer to other files. Do you want to update the fields in this document?"
+ * (if "Update automatic links at open" is enabled)
+ * - Flag is removed after saving with changes in Word
+ *
+ */
+ public void setUpdateFields() {
+ CTOnOff onOff = CTOnOff.Factory.newInstance();
+ onOff.setVal(STOnOff.TRUE);
+ ctSettings.setUpdateFields(onOff);
+ }
+
@Override
protected void commit() throws IOException {
--- src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (revision 1151345)
+++ src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (working copy)
@@ -1016,6 +1016,22 @@
}
/**
+ * Enforces fields update on document open (in Word).
+ * In the settings.xml file
+ * sets the updateSettings value to true (w:updateSettings w:val="true")
+ *
+ * NOTICES:
+ *
+ * - Causing Word to ask on open: "This document contains fields that may refer to other files. Do you want to update the fields in this document?"
+ * (if "Update automatic links at open" is enabled)
+ * - Flag is removed after saving with changes in Word
+ *
+ */
+ public void enforceUpdateFields() {
+ settings.setUpdateFields();
+ }
+
+ /**
* inserts an existing XWPFTable to the arrays bodyElements and tables
* @param pos
* @param table