Page 1 of 1

How to collect styles that are included into Words Navigatio

PostPosted: Thu Feb 14, 2013 9:29 pm
by zkoppanylist
Hi everybody,

how can I collect the styles that are displayed in Word's Navigation View (please check screen-shot)?

I need to provide a (html) view similar to the screen-shot.

Regards,

Zsolt

Re: How to collect styles that are included into Words Navig

PostPosted: Thu Feb 14, 2013 11:49 pm
by jason

Re: How to collect styles that are included into Words Navig

PostPosted: Fri Feb 15, 2013 12:05 am
by zkoppanylist
The code below always return null into variable "outline":

P paragraph ....
PPr ppr = paragraph.getPPr();
OutlineLvl outline = ppr.getOutlineLvl();

Re: How to collect styles that are included into Words Navig

PostPosted: Fri Feb 15, 2013 12:56 pm
by jason
It could be there, or more likely, in the pPr part of the style definition. Have a look at the definition of Heading 1 for example, in your styles part.

Re: How to collect styles that are included into Words Navig

PostPosted: Tue Feb 19, 2013 2:44 am
by zkoppanylist
Here is the code I use:

protected void processDefaultOutlineStyles() {
if (outlineStyles == null) {
outlineStyles = new HashSet<String>();

boolean isDebug = logger.isDebugEnabled();
for (Style style : getStyleDefinitionsPart().getJaxbElement().getStyle()) {
PPr ppr = style.getPPr();
OutlineLvl outline = ppr == null ? null : ppr.getOutlineLvl();

if (isDebug) {
String outLineVal = outline == null || outline.getVal() == null ? "#" : outline.getVal().toString();
String styleName = style.getName() == null || style.getName().getVal() == null ? "#" : style.getName().getVal().toString();
logger.debug("styleId <" + style.getStyleId() + "> name <" + styleName + "> type <" + style.getType() + "> outline: " + outLineVal);
}
if (style.getPPr() != null && style.getPPr().getOutlineLvl() != null && style.getPPr().getOutlineLvl().getVal() != null) {
outlineStyles.add(style.getStyleId());
}
}
}
}

In the log I see styles as below:

2 DEBUG docx.DocxToWiki - styleId <style0> name <Normal> type <paragraph> outline: #
2 DEBUG docx.DocxToWiki - styleId <style1> name <Heading 1> type <paragraph> outline: #
2 DEBUG docx.DocxToWiki - styleId <style2> name <Heading 2> type <paragraph> outline: 1
2 DEBUG docx.DocxToWiki - styleId <style3> name <Heading 3> type <paragraph> outline: 2
2 DEBUG docx.DocxToWiki - styleId <style4> name <Heading 4> type <paragraph> outline: 3
2 DEBUG docx.DocxToWiki - styleId <style5> name <Heading 5> type <paragraph> outline: 4
2 DEBUG docx.DocxToWiki - styleId <style15> name <Default Paragraph Font> type <character> outline: #
2 DEBUG docx.DocxToWiki - styleId <style16> name <Überschrift 1 Zchn> type <character> outline: #
2 DEBUG docx.DocxToWiki - styleId <style17> name <Überschrift 2 Zchn> type <character> outline: #
2 DEBUG docx.DocxToWiki - styleId <style18> name <Überschrift 3 Zchn> type <character> outline: #
2 DEBUG docx.DocxToWiki - styleId <style19> name <Überschrift 4 Zchn> type <character> outline: #
3 DEBUG docx.DocxToWiki - styleId <style20> name <Überschrift 5 Zchn> type <character> outline: #
3 DEBUG docx.DocxToWiki - styleId <style21> name <Heading> type <paragraph> outline: #
3 DEBUG docx.DocxToWiki - styleId <style22> name <Text body> type <paragraph> outline: #
3 DEBUG docx.DocxToWiki - styleId <style23> name <List> type <paragraph> outline: #
3 DEBUG docx.DocxToWiki - styleId <style24> name <Caption> type <paragraph> outline: #
3 DEBUG docx.DocxToWiki - styleId <style25> name <Index> type <paragraph> outline: #

I attach the screen-shot of the Navigation View and the document itself.

Re: How to collect styles that are included into Words Navig

PostPosted: Tue Feb 19, 2013 8:05 am
by jason
If you look at styles.xml in that docx, Heading 1 has no w:outlineLvl

I see your docx was created with LibreOffice/3.5; Word would have put an w:outlineLvl value there.

Evidently Word has special logic built into it that recognises w:name/@w:val="Heading 1" as level 0:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  <w:style w:styleId="style1" w:type="paragraph">
    <w:name w:val="Heading 1"/>
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


because if you change the name in styles.xml, it disappears from the navigation pane.

Re: How to collect styles that are included into Words Navig

PostPosted: Tue Feb 19, 2013 9:31 pm
by zkoppanylist
Thank you Jason very much!

Regards,

Zsolt

Re: How to collect styles that are included into Words Navig

PostPosted: Thu Feb 21, 2013 1:07 am
by zkoppanylist
In the attached styles.xml I have (also) the entries below:

<w:style w:type="paragraph" w:styleId="berschrift1"><w:name w:val="heading 1"/><w:basedOn w:val="Standard"/><w:next w:val="Text"/>
...
<w:style w:type="paragraph" w:customStyle="1" w:styleId="BUCScenario"><w:name w:val="BUC_Scenario"/><w:basedOn w:val="berschrift1"/>

Word displays "berschrift1" and "BUCScenario" style elements under Navigation. I do understand "berschrift1" because that style is reported having OutlineLvl 1 (via wordMLPackage.getMainDocumentPart().getStyleDefinitionsPart().getJaxbElement().getStyle()).

"BUCScenario" style is based on "berschrift1" however its OutlineLvl is reported as null.

Is that a bug or feature?

Unfortunately I cannot provide the (customer) Word document just styles.xml that I had to compress to upload it.