Page 1 of 1

how to add new row?

PostPosted: Tue Jul 21, 2015 4:03 pm
by yangcom0505
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);
            }
         }
      }

Re: how to add new row?

PostPosted: Fri Jul 24, 2015 6:18 pm
by jason
Well, your code

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
            Tbl newTbl = (Tbl) XmlUtils.deepCopy(sourceTbl);
            :
            body.getContent().add(newTbl);
 
Parsed in 0.014 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