Page 1 of 1

Heading style supporting

PostPosted: Sun Feb 15, 2015 11:57 am
by pengppp11
Hello

I met a problem of converting heading styles like h1,h2 into docx. I have set "docx4j-ImportXHTML.Element.Heading.MapToStyle=true". If there is newly created WordprocessingMLPackage(e.g. wordprocessingMLPackage = WordprocessingMLPackage.createPackage() ), the heading styles can be properly converted into final docx. However, if those styles are converted into an existing WordprocessingMLPackage on disk, only bold style can be shown into the generated docx. Is there possible to still convert or match the heading styles into an existing docx :?

Re: Heading style supporting

PostPosted: Mon Feb 16, 2015 7:10 pm
by jason
The heading styles must be pre-defined in the styles part in your existing WordprocessingMLPackage.

Please verify they are there. (Unzip the docx and look at the word/styles.xml part contents)

Re: Heading style supporting

PostPosted: Wed Feb 18, 2015 2:55 am
by pengppp11
Hello Jason, thanks for your reply

I checked the style.xml, it locates at the right place. And following is the fragment:

Code: Select all
<w:latentStyles w:defLockedState="0" w:defUIPriority="99" w:defSemiHidden="1" w:defUnhideWhenUsed="1" w:defQFormat="0" w:count="267">
  <w:lsdException w:name="Normal" w:semiHidden="0" w:uiPriority="0" w:unhideWhenUsed="0" w:qFormat="1"/>
  <w:lsdException w:name="heading 1" w:semiHidden="0" w:uiPriority="9" w:unhideWhenUsed="0" w:qFormat="1"/>
  <w:lsdException w:name="heading 2" w:uiPriority="9" w:qFormat="1"/>
  <w:lsdException w:name="heading 3" w:uiPriority="9" w:qFormat="1"/>
  <w:lsdException w:name="heading 4" w:uiPriority="9" w:qFormat="1"/>
  <w:lsdException w:name="heading 5" w:uiPriority="9" w:qFormat="1"/>
  <w:lsdException w:name="heading 6" w:uiPriority="9" w:qFormat="1"/>
   ****and more****
</w:latentStyles>


This style.xml is the part of a default docx directly created in MS-Word 2007, I have uploaded this docx file in the attachment. If I convert e.g. <html><h1>1</h1><h2>2</h2>3</html> into this docx, only bold style can be converted. I compared the style.xml created by Docx4j (e.g. WordprocessingMLPackage.createPackage()), there are less <w:lsdException> entries, I'm not sure whether this is the reason that docx4j-ImportXHTML can't transform those heading styles.

Re: Heading style supporting

PostPosted: Wed Feb 18, 2015 8:38 am
by jason
No, that is not a style definition.

You are looking for something like:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  <w:style w:type="paragraph" w:styleId="Heading1">
    <w:name w:val="heading 1"/>
    <w:basedOn w:val="Normal"/>
    <w:next w:val="Normal"/>
    <w:link w:val="Heading1Char"/>
    <w:uiPriority w:val="9"/>
    <w:qFormat/>
    <w:rsid w:val="00963AEA"/>
    <w:pPr>
      <w:keepNext/>
      <w:keepLines/>
      <w:spacing w:before="480" w:after="0"/>
      <w:outlineLvl w:val="0"/>
    </w:pPr>
    <w:rPr>
      <w:rFonts w:asciiTheme="majorHAnsi" w:eastAsiaTheme="majorEastAsia" w:hAnsiTheme="majorHAnsi" w:cstheme="majorBidi"/>
      <w:b/>
      <w:bCs/>
      <w:color w:val="365F91" w:themeColor="accent1" w:themeShade="BF"/>
      <w:sz w:val="28"/>
      <w:szCs w:val="28"/>
    </w:rPr>
  </w:style>
 
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


Note w:styleId="Heading1"