Page 1 of 1

Problem styling list generated using AlternativeFormatInputP

PostPosted: Wed Sep 21, 2011 5:05 am
by SGhosh
We have a requirement to generate MS-Word file from content stored into different database tables. Some of these content are HTML snippets (well formed HTML). I have managed to create the required Word document by using AlternativeFormatInputPart.

Now the problem I'm facing is styling some of these text segments. In particular, one of the HTML fragments contain multilevel list elements - they are being rendered as such in the generated document. But I need to style them differently - for example, change w:ind left and hanging values, w:lvlText values etc.

I followed the example in NumberingRestart.java code to create a new w:Numbering element with some of my formatting requirement. But the generated document still renders in the default way.

I saved the generated document in Word 2003 XML format and when I look at the content, I noticed that there were two w:listDef elements. The NumberingDefinitionPart I created in my code has generated <w:listDef w:listDefId="1"> element. However, there is another <w:listDef w:listDefId="0"> element just prior to this one - and the list is being rendered using this one.

If I manually remove the <w:listDef w:listDefId="0"></w:listDef> element and rename <w:listDef w:listDefId="1"> to <w:listDef w:listDefId="0">, I can see that my intended formatting is working.

Can you please suggest a way to work around this issue?

I'm attaching the sample code illustrating the problem - I'm using docx4j 2.7.0.

Thanks
Suman

Re: Problem styling list generated using AlternativeFormatIn

PostPosted: Wed Sep 21, 2011 8:08 am
by jason
Try adding CSS in a style attribute in your HTML - this may or may not work.

Failing that, you could convert your ul-tags to paragraph tags in the HTML, and in your docx have a style with the same name as the class-name in HTML. See http://openxmldeveloper.org/discussions ... /8464.aspx

Failing this, you'll need to forget the altChunk approach, and instead convert the HTML to WordML yourself, and insert that.

Re: Problem styling list generated using AlternativeFormatIn

PostPosted: Wed Sep 21, 2011 8:19 am
by SGhosh
Thanks Jason. I'll see if the suggested solutions work.

In the meantine, can you please shed some light on why the <w:listDef w:listDefId="0"> element is being created even though I explicitly wanted to create the other one.

Suman