(The open source Java library for manipulating docx files)
by yangcom0505 » Tue Jul 21, 2015 4:03 pm
hi all
I'm trying to add row in table.
i did add table.
but i want to add row not table.
thanks!
- Code: Select all
org.docx4j.wml.Document wmlDocumentEl = (org.docx4j.wml.Document) wordMLPackage
.getMainDocumentPart().getJaxbElement();
Body body = wmlDocumentEl.getBody();
ObjectFactory factory = Context.getWmlObjectFactory();
if (exportListItem != null) {
List<Object> tables1 = getAllElementFromObject(
wordMLPackage.getMainDocumentPart(), Tbl.class);
if (tables1 != null) {
Tbl sourceTbl = (Tbl) tables1.get(0);
Tbl newTbl = (Tbl) XmlUtils.deepCopy(sourceTbl);
//body.getContent().remove(sourceTbl.getParent());
for (int i = 0; i < exportListItem.size(); i++) {
body.getContent().add(newTbl);
}
}
}
-
yangcom0505
-
- Posts: 11
- Joined: Tue Jul 14, 2015 8:00 pm
by jason » Fri Jul 24, 2015 6:18 pm
Well, your code
Using java Syntax Highlighting
Tbl newTbl
= (Tbl
) XmlUtils.
deepCopy(sourceTbl
);
:
body.
getContent().
add(newTbl
);
Parsed in 0.013 seconds, using
GeSHi 1.0.8.4
is obviously going to add a table.
To add a row to a table, upload a sample docx to the online webapp to generate code.
Or see line 82 of
https://github.com/plutext/docx4j/blob/ ... ctory.java
-
jason
-
- Posts: 4085
- Joined: Wed Mar 19, 2008 11:47 pm
Return to docx4j
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], GTPBot, Majestic-12 [Bot] and 127 guests