Page 1 of 1

styles in list, problem

PostPosted: Wed Aug 24, 2011 9:34 am
by naked11
I have this method:

Code: Select all
public List getListOfPara() {
        ArrayList<Para> listPara = new ArrayList<Para>();
       
        List so = new ArrayList();
        so = dokument.getMainDocumentPart().getJAXBNodesViaXPath("//w:p", false);
        Iterator itOds = so.iterator();
        while (itOds.hasNext()) {
            P ods = (P) itOds.next();
            Style st =getStyleofPara(ods); //it works well, got right style
            String text = vratTextOdstavce(ods);
            Para odsa = new Para(st, text);      [b]//write properties of style works well[/b], it is right style
            listPara.add(odsa);
//also right style
        }
//but here, styles from the list listPara is different paragraphs(with right content) but with all same styles
//styles of all paragraphs are the same, but in while cykle it was right styles
        return listPara;
    }

where is the error/mistake?


Code: Select all
//Para class
public class Para {

    private Style stylePara;
    private String textPara;

//constructor
    public Odstavec(Style stylePara, String textPara) {
        this.stylePara = stylePara;
        this.textPara = textPara;
    }}

Re: styles in list, problem

PostPosted: Wed Aug 24, 2011 10:10 am
by jason
Hard to say what is going wrong without seeing the XML representing the style and the XML representing the paragraphs, but I guess you are missing some direct formatting eg a w:numPr element.

Code: Select all
<w:numPr>
        <w:numId w:val="1"/>
      </w:numPr>


You can always use XmlUtils.marshaltoString to see what you've created, and compare that to what you want...

Re: styles in list, problem

PostPosted: Wed Aug 24, 2011 11:01 am
by naked11
Is it necessarry give to style all direct formatting?

for example, one of my styles:

TO XML
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<w:style xmlns:ns25="http://schemas.openxmlformats.org/drawingml/2006/compatibility" xmlns:ns26="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:ns24="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:odx="http://opendope.org/xpaths" xmlns:odgm="http://opendope.org/SmartArt/DataHierarchy" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:ns17="urn:schemas-microsoft-com:office:powerpoint" xmlns:ns15="urn:schemas-microsoft-com:office:excel" xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:odi="http://opendope.org/components" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:ns6="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:odq="http://opendope.org/questions" xmlns:ns11="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:ns8="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:odc="http://opendope.org/conditions"><w:rPr><w:rFonts w:hAnsi="Book Antiqua" w:ascii="Book Antiqua"/><w:b/><w:bCs/><w:i/><w:iCs/><w:sz w:val="32"/><w:szCs w:val="32"/><w:vertAlign w:val="subscript"/><w:lang w:eastAsia="de-AT" w:val="de-AT"/></w:rPr></w:style>
 
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


TO XML
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
<w:style xmlns:ns25="http://schemas.openxmlformats.org/drawingml/2006/compatibility" xmlns:ns26="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas" xmlns:ns24="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:odx="http://opendope.org/xpaths" xmlns:odgm="http://opendope.org/SmartArt/DataHierarchy" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:ns17="urn:schemas-microsoft-com:office:powerpoint" xmlns:ns15="urn:schemas-microsoft-com:office:excel" xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:odi="http://opendope.org/components" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:ns6="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:odq="http://opendope.org/questions" xmlns:ns11="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:ns8="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:odc="http://opendope.org/conditions"><w:rPr><w:rFonts w:hAnsi="Book Antiqua" w:ascii="Book Antiqua"/><w:b/><w:bCs/><w:i/><w:iCs/><w:sz w:val="32"/><w:szCs w:val="32"/><w:vertAlign w:val="subscript"/><w:lang w:eastAsia="de-AT" w:val="de-AT"/></w:rPr></w:style>
 
Parsed in 0.002 seconds, using GeSHi 1.0.8.4

Re: styles in list, problem

PostPosted: Wed Aug 24, 2011 11:11 am
by naked11
styles seem to be right XML format...
problem is, that after while cykle, each paragraphs have the same style(the last one), but in the cykle it was right styles..

method that got styles of paragraph-->


stylOdstavce = dokument.getMainDocumentPart().getStyleDefinitionsPart().getDefaultParagraphStyle();
PPr pProp = dokument.getMainDocumentPart().getStyleDefinitionsPart().getDefaultParagraphStyle().getPPr();
RPr prop = dokument.getMainDocumentPart().getStyleDefinitionsPart().getDefaultParagraphStyle().getRPr();
stylOdstavce.setPPr(pProp);
stylOdstavce.setRPr(prop);
Iterator itObsOds = odstavec.getContent().iterator();
while (itObsOds.hasNext()) {
Object o = itObsOds.next();
if (o instanceof R) {
R run = (R) o;
StyleUtil.apply(run.getRPr(), prop);
}
}
stylOdstavce.setRPr(prop);

Re: styles in list, problem

PostPosted: Thu Aug 25, 2011 10:45 pm
by jason
The 2 w:style elements you show are missing at least @w:type, @w:styleId, and w:name child element, so they can't be used.

However you created them, please compare to a styles.xml part from a docx saved from Word.