How to create Nested tables in MS word using XWPFTable -
i need create table within table cell in ms word using java. using code
public class helloworldtable { public static void main(string[] args) throws ioexception { file file = new file("webcontent/mswordtemplates/welcomelettertable.doc"); poifsfilesystem fs = new poifsfilesystem(new fileinputstream(file)); string name="gaurav"; string letterbody="congratulations "; xwpfdocument document = new xwpfdocument(); xwpftable tableone = document.createtable(); xwpftable table2 = document.createtable(); xwpftablerow tableonerowone = tableone.getrow(0); xwpftablerow tableonerow2 = tableone.createrow(); xwpftablerow tableonerow3 = tableone.createrow(); xwpftablerow tableonerow4 = tableone.createrow(); xwpftablerow tableonerow5 = tableone.createrow(); xwpftablerow tableonerow6 = tableone.createrow(); xwpftablerow tableonerow7 = tableone.createrow(); xwpftablerow tableonerow8 = tableone.createrow(); xwpftablerow tableonerow9 = tableone.createrow(); tableonerowone.getcell(0).settext(""); tableonerow2.getcell(0).settext(""); tableonerow3.getcell(0).settext(""); tableonerow4.getcell(0).inserttable(0,table2); xwpftablerow table2row1 = table2.getrow(0); table2row1.getcell(0).settext("hi"); table2row1.createcell().settext(name); tableonerow5.getcell(0).settext(letterbody); tableonerow6.getcell(0).settext(""); tableonerow7.getcell(0).settext(""); tableonerow8.getcell(0).settext(""); tableonerow9.getcell(0).settext(""); outputstream out = new fileoutputstream(new file("c:/users/gsaxena/desktop/w7.doc")); document.write(out); out.flush(); out.close(); } }
in line tableonerow4.getcell(0).inserttable(0,table2); tried use insertable option same gave me following error. removed part of code , rest run fine section of code contains error sure, not have solution it.
exception in thread "main" java.lang.noclassdeffounderror: org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.cttcimpl$1tbllist @ org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.cttcimpl.gettbllist(unknown source) @ org.apache.poi.xwpf.usermodel.xwpftablecell.inserttable(xwpftablecell.java:396) @ readandwrite.helloworldtable.main(helloworldtable.java:42) caused by: java.lang.classnotfoundexception: org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.cttcimpl$1tbllist @ java.net.urlclassloader.findclass(urlclassloader.java:419) @ java.lang.classloader.loadclass(classloader.java:643) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:345) @ java.lang.classloader.loadclass(classloader.java:609) ... 3 more please help,thanks in advance
Comments
Post a Comment