Here is the code (some of it) that I pulled from the document.xml file which contained the table I created:
- Code: Select all
String tableProperties = "<w:tblPr " + Namespaces.W_NAMESPACE_DECLARATION
+ ">" + "<w:tblStyle w:val=\"TableGrid\"/>"
+"<w:tblW w:w=\"0\" w:type=\"auto\"/>"+"<w:tblBorders>"
+"<w:top w:val=\"none\" w:sz=\"0\" w:space=\"0\" w:color=\"auto\" /> "
+"<w:left w:val=\"none\" w:sz=\"0\" w:space=\"0\" w:color=\"auto\" /> "
+"<w:bottom w:val=\"none\" w:sz=\"0\" w:space=\"0\" w:color=\"auto\" /> "
+"<w:right w:val=\"none\" w:sz=\"0\" w:space=\"0\" w:color=\"auto\" /> "
+"<w:insideH w:val=\"none\" w:sz=\"0\" w:space=\"0\" w:color=\"auto\" /> "
+"<w:insideV w:val=\"none\" w:sz=\"0\" w:space=\"0\" w:color=\"auto\" /> "
+"</w:tblBorders>"
+ "<w:tblLook w:val=\"04A0\"/>" + "</w:tblPr>";
This sets up the generic table but the alignment is default to the left which doesn't fix the problem. This part works as expected, though.
Here is the code that I believe would be necessary to set up the right alignment, by perhaps accessing each individual cell and setting the properties? :
- Code: Select all
String tableContents = "stringThatWouldChange";
String rowUnmarshaled = "<w:tc> "
+" <w:tcPr>"
+" <w:tcW w:w=\"1504\" w:type=\"dxa\" /> "
+" <w:vAlign w:val=\"center\" /> "
+" </w:tcPr> "
+" <w:p w:rsidR=\"00D53843\" w:rsidRDefault=\"009229D7\" w:rsidP=\"00A01E30\"> "
+" <w:pPr> "
+" <w:jc w:val=\"right\" /> "
+" </w:pPr> "
+" <w:proofErr w:type=\"spellStart\" /> "
+" <w:r> "
+" <w:t>" + tableContents + "</w:t> "
+" </w:r> "
+" <w:proofErr w:type=\"spellEnd\" /> "
+" </w:p> "
+" </w:tc>";
TcPr rowProperties = null;
rowProperties = (TcPr) XmlUtils.unmarshalString(rowUnmarshaled);
Here are my questions:
First, is there a very easy way that I could just add some extra XML in my first block of code to make all of the alignment in my table to the right?
If this is not the case, can I somehow access just the paragraph portion of each cell, changing the alignment to right with a few lines of code like this? :
- Code: Select all
String pPr = "<w:pPr> "
+ "<w:jc w:val=\"right\"/> "
+ "</w:pPr>";
Finally, if my original suspicion was correct and I in fact DO have to access each individual cell and generate the properties individually, what is the method to access the properties? Am I dealing with TcPr?
Thanks in advance.