diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index e374a544d..42050460b 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,8 @@ + support setting background color of sheet tab in XSSF + 51564 - support for enforcing fields update in XWPF 51673 - support grouping rows in SXSSF 51780 - support replacement of content types in OPC packages 52784 - replace ISO control characters with question marks in SXSSF to be consistent with XSSF diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java index 94b326811..3114813f5 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -974,6 +974,10 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { return settings.isEnforcedWith(STDocProtect.TRACKED_CHANGES); } + public boolean isEnforcedUpdateFields() { + return settings.isUpdateFields(); + } + /** * Enforces the readOnly protection.
* In the documentProtection tag inside settings.xml file,
@@ -1047,6 +1051,22 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { settings.removeEnforcement(); } + /** + * 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: + * + */ + public void enforceUpdateFields() { + settings.setUpdateFields(); + } + /** * inserts an existing XWPFTable to the arrays bodyElements and tables * @param pos diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java index 5471fde0c..8ceddbe35 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java @@ -30,6 +30,7 @@ import org.apache.poi.openxml4j.opc.PackagePart; 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,28 @@ public class XWPFSettings extends POIXMLDocumentPart { 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: + * + */ + public void setUpdateFields() { + CTOnOff onOff = CTOnOff.Factory.newInstance(); + onOff.setVal(STOnOff.TRUE); + ctSettings.setUpdateFields(onOff); + } + + boolean isUpdateFields() { + return ctSettings.isSetUpdateFields() && ctSettings.getUpdateFields().getVal() == STOnOff.TRUE; + } + @Override protected void commit() throws IOException { if (ctSettings == null) { diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java b/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java index 3e3d93f33..3d814aada 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/TestDocumentProtection.java @@ -137,4 +137,11 @@ public class TestDocumentProtection extends TestCase { assertTrue(document.isEnforcedCommentsProtection()); } + public void testUpdateFields() throws Exception { + XWPFDocument doc = new XWPFDocument(); + assertFalse(doc.isEnforcedUpdateFields()); + doc.enforceUpdateFields(); + assertTrue(doc.isEnforcedUpdateFields()); + } + }