I have a docx "template" with one table that has several columns in one row. Using Word the table is setup and the default font is overriden to Courier New (or any font really...the user is in control and the code will never know ahead of time). No text is typed into any column. The docx is saved (all with Word app, no code yet).
This is what the w:tc looks like at this point:
- Code: Select all
<w:tc><w:tcPr><w:tcW w:w="2610" w:type="dxa"/></w:tcPr><w:p w:rsidR="001C6C68" w:rsidRPr="001C6C68" w:rsidRDefault="001C6C68" w:rsidP="001C6C68"><w:pPr><w:rPr><w:rFonts w:ascii="Courier New" w:hAnsi="Courier New" w:cs="Courier New"/></w:rPr></w:pPr></w:p></w:tc>
There is no existing run for me to work with as no text was typed, just a font was set.
Then using dox4j I open the docx and add text to one of the columns. After that, the w:tc looks like this:
- Code: Select all
<w:tc><w:tcPr><w:tcW w:type="dxa" w:w="2610"/></w:tcPr><w:p w:rsidRDefault="001C6C68" w:rsidP="001C6C68" w:rsidR="001C6C68" w:rsidRPr="001C6C68"><w:pPr><w:rPr><w:rFonts w:cs="Courier New" w:hAnsi="Courier New" w:ascii="Courier New"/></w:rPr></w:pPr><w:r><w:t>TEST ADD DATA TO COLUMN 2</w:t></w:r></w:p></w:tc>
The run that I add to the pargraph is being added after the closing w:pPr, so my font settings get ignored and the default docx font takes over.
I found that I can set the font by doing this:
- Code: Select all
runRpr.setRFonts(paragraph.getPPr().getRPr().getRFonts());
Where runRpr is a new RPr and paragraph is an instance of the P I found in the Tc.
Will I have to do that for everything about the style of the P? Is there any easy way to inherit the entire style of the P when I don't know it ahead of time?
Thanks.