Page 1 of 1

how to create rows and columns in a word table using docx4j.

PostPosted: Thu Jul 17, 2014 9:48 pm
by jignesh
I am a beginner in docx4j and I would appreciate any help with generating word document table using docx4j.

I have had a look at the sample code org.docx4j.samples.CreateWordprocessingMLDocument in 2.7.1 provided in this link
http://grepcode.com/file/repo1.maven.org/maven2/org.docx4j/docx4j/2.7.1/org/docx4j/samples/CreateWordprocessingMLDocument.java?av=f

This is what I have done
Code: Select all
         // Add a table
         
         int writableWidthTwips = wordMLPackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips();
         int cols = 5;
         int cellWidthTwips = new Double(Math.floor((writableWidthTwips/cols))).intValue();
         
         Tbl tbl = TblFactory.createTable(1, 5, cellWidthTwips);
         wordMLPackage.getMainDocumentPart().addObject(tbl);

I have managed to create a table using this sample. But I do not have any idea how can I create rows, columns and insert value into cells?

I will appreciate any sample code for that or any documentation which can help me to get on with this.

Thanks in advance