Page 1 of 1

Adding Title/Caption/Header to a Table

PostPosted: Sat Feb 11, 2012 4:00 am
by sureshbabubv
Dear All,

Please suggest me how to a caption/title/header for a table by generating it through docx4j api.

Thanks & Regards,
B.V.Suresh Babu.

Re: Adding Title/Caption/Header to a Table

PostPosted: Sat Feb 25, 2012 3:13 am
by sureshbabubv
Dear All,

I resolved this by using the following code

Code: Select all
org.docx4j.wml.ObjectFactory factory = new org.docx4j.wml.ObjectFactory();

   Tbl tbl = factory.createTbl();


String StrTblHeaderRow="<w:tr xmlns:wpc=\"http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas\" xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:m=\"http://schemas.openxmlformats.org/officeDocument/2006/math\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:wp14=\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\" xmlns:w10=\"urn:schemas-microsoft-com:office:word\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:w14=\"http://schemas.microsoft.com/office/word/2010/wordml\" xmlns:wpg=\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\" xmlns:wpi=\"http://schemas.microsoft.com/office/word/2010/wordprocessingInk\" xmlns:wne=\"http://schemas.microsoft.com/office/word/2006/wordml\" xmlns:wps=\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\" w:rsidR=\"00352B95\"><w:trPr><w:cantSplit/><w:tblHeader/><w:jc w:val=\"center\"/></w:trPr><w:tc><w:tcPr><w:tcW w:w=\"9360\" w:type=\"dxa\"/><w:gridSpan w:val=\"6\"/><w:tcBorders><w:top w:val=\"nil\"/><w:left w:val=\"nil\"/><w:bottom w:val=\"single\" w:sz=\"4\" w:space=\"0\" w:color=\"auto\"/><w:right w:val=\"nil\"/></w:tcBorders></w:tcPr><w:p w:rsidR=\"00352B95\" w:rsidRDefault=\"00352B95\"><w:pPr><w:spacing w:after=\"240\"/><w:jc w:val=\"center\"/></w:pPr><w:r><w:rPr><w:rStyle w:val=\"tocheader1\"/></w:rPr><w:t>Table Header Row</w:t></w:r></w:p></w:tc></w:tr>";
   
   StrTblHeaderRow = StrTblHeaderRow.replaceAll("&", "&");

   Tr objTr = (Tr) XmlUtils
         .unmarshalString(StrTblHeaderRow, Context.jc,
               Tr.class);
   
   tbl.getContent().add(objTr);


Add this row as starting row to the table, then add your header row, data rows.

Thanks & Regards,
B.V.Suresh Babu.

Re: Adding Title/Caption/Header to a Table

PostPosted: Thu Jan 31, 2013 8:24 am
by jason