Related blog post: Edit Word Documents in Java
Last active
April 3, 2022 05:39
-
-
Save GroupDocsGists/4946a7e2b81db6af1799cdb151100052 to your computer and use it in GitHub Desktop.
How to Edit Word Document in 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
// Edit the Word DOC/DOCX documents in Java | |
Options.WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions(); | |
loadOptions.setPassword("password-if-any"); | |
Editor editor = new Editor("path/document.docx", loadOptions); | |
EditableDocument defaultWordProcessingDoc = editor.edit(); | |
// Either edit using any WYSIWYG editor or edit programmatically | |
String allEmbeddedInsideString = defaultWordProcessingDoc.getEmbeddedHtml(); | |
String allEmbeddedInsideStringEdited = allEmbeddedInsideString.replace("document", "edited document"); | |
// Save the edited document | |
EditableDocument editedDoc = EditableDocument.fromMarkup(allEmbeddedInsideStringEdited, null); | |
WordProcessingSaveOptions saveOptions = new WordProcessingSaveOptions(WordProcessingFormats.Docx); | |
editor.save(editedDoc, "path/edited-document.docx", saveOptions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment