This repository shows how to edit a Word table programmatically with GroupDocs.Editor for Java: change cell text and table borders, then save back to DOCX.
GroupDocs does not give you raw DOCX XML. It converts the document to HTML + CSS so you can edit it like a web page:
flowchart LR
A[input.docx] --> B["Editor.edit()"]
B --> C[EditableDocument]
C --> D["getBodyContent()"]
C --> E["getCssContent()"]
C --> F["style.css, fonts, …"]
D --> G["Edit cell text"]
E --> H["Edit table borders"]
F --> I["Save resources folder"]
G --> J["fromMarkupAndResourceFolder()"]
H --> I
I --> J
J --> K["editor.save()"]
K --> L[output.docx]
Important: table text is in the body HTML; table borders are usually in style.css. If you only edit the body and call fromMarkup(body) without the CSS folder, borders will be wrong or missing.
| Part | API | Change |
|---|---|---|
| Cell status text | getBodyContent() |
Review → Supported |
| Section title | getBodyContent() |
“before HTML edit” → “after HTML table edit” |
| Table borders | getCssContent() |
stronger border on table.table001 and cells |
See ManageTablesInHtmlExample.java — the run() method is written as Steps 1–8 with comments.
- Java 8 or higher
- Maven 3.x
- Input file:
resources/input/input.docx(create withpython scripts/create_input_docx.pyif needed)
Free temporary license or purchase. Optional file: groupdocs.editor.lic in the project root.
mvn compile exec:javaOutput: resources/output/output.docx
Q: Why not use getEmbeddedHtml()?
A: That returns one big HTML string with all resources embedded. Splitting body and CSS is closer to how WYSIWYG editors work and is easier to understand.
Q: Can I edit merged cells?
A: Yes — merged cells use rowspan / colspan in the body HTML from getBodyContent().
Q: Will replace() work on any document?
A: The sample uses fixed strings from our demo input.docx. For real documents, inspect body/CSS once (print to console) and adjust the strings you replace.