Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support updating DOCVARIABLE fields on document surface.
- Loading branch information
Showing
3 changed files
with
54 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
docx4j-samples-docx4j/src/main/java/org/docx4j/samples/DocPropertyFieldUpdater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.docx4j.samples; | ||
|
||
import org.docx4j.XmlUtils; | ||
import org.docx4j.model.fields.FieldUpdater; | ||
import org.docx4j.openpackaging.exceptions.Docx4JException; | ||
import org.docx4j.openpackaging.packages.WordprocessingMLPackage; | ||
|
||
/** | ||
* Example showing how to refresh DOCPROPERTY and DOCVARIABLE | ||
* fields in the docx. | ||
* (For MERGEFIELD, use FieldsMailMerge instead) | ||
* | ||
* This updates the docx. If you don't want to do | ||
* that, apply it to a clone instead. | ||
*/ | ||
public class DocPropertyFieldUpdater { | ||
|
||
public static void main(String[] args) throws Docx4JException { | ||
|
||
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load( | ||
new java.io.File( | ||
System.getProperty("user.dir") + "/DocProp.docx")); | ||
|
||
FieldUpdater fu = new FieldUpdater(wordMLPackage); | ||
fu.update(true); | ||
|
||
System.out.println(XmlUtils.marshaltoString(wordMLPackage.getMainDocumentPart().getJaxbElement(), true, true)); | ||
|
||
} | ||
|
||
} |