Page 1 of 1

xhtml fragments into existing word document

PostPosted: Fri May 23, 2014 9:24 am
by jspriggs
I have an existing word document that we take user input from a web application to fill out completely for the user to download. It's a pretty large word document, and the application takes a lot of input. We had previously been building the word document with HTML that gets converted to a docx, but it seems easier just to use docx4j. I've had some good success with just taking the original sample document from our client and adding bookmarks to the points where we need the data entry to be popped in place.

The reason we have to deal with html is there are points where we allow user entry of rich text that gets saved to our database as html formatted text. So, I've been hacking together the samples for xhtml import to get a list of paragraph elements and appending it into the document at the point of the bookmarks.

The problem is I've got a segment of html that is an ordered list, when I append the parts in, it's losing the list basically. If I dump out the contents of what was imported into the list object from xhtmlimporter, it looks like the list is there, but when it's appended at the bookmark it's gone.

Here's the function I currently have to replace a single bookmark as a test:

Sorry if it's a little messy and it is ColdFusion since its our primary language and this was a feasibility test. Paragraphs is the bodycontents of the word doc and the datatext var is the list returned from xhtmlimporter.convert.

Code: Select all
   
function replaceBookmarkContents(paragraphs, bookmarkName, dataText, XMLUtils, factory) {
        pStyle = factory.createPPrBasePStyle();
        pStyle.setVal("Normal");
        bigInt = createObject( "java", "java.math.BigInteger" );
        size = loader.create("org.docx4j.wml.HpsMeasure");
        size.setVal(bigInt.valueOf(24));
        pprbaseind = factory.createPPrBaseInd();
        pprbaseind.setLeft( bigInt.valueOf( 720) );

        rt = loader.create("org.docx4j.finders.RangeFinder").init("CTBookmark", "CTMarkupRange");
        loader.create("org.docx4j.TraversalUtil").init(paragraphs, rt);
        bookmarks = rt.getStarts();
        for(i = 0; i < bookmarks.size(); i++) {
            bm = bookmarks.get(i);

            if(bm.getName() == javacast("null",'')) {
                continue;
            }
                if(bm.getName() eq 'SectionASuccessNarrative') {
                    bmparent = bm.getParent();
                    if(bmparent.getClass().getName() eq "org.docx4j.wml.P") {
                        theList = bmParent.getContent();
                    } else {
                        continue;
                    }

                    bmparentList = bmParent.getParent();
                    bookmarkIndex = bmparentList.indexOf(bmparent);


                    for(datas = 0; datas < dataText.size(); datas++) {
                        paragraph = dataText.get(datas);
                        ppr = paragraph.getPPr();
                        ppr.setInd(pprbaseind);
                        recursiveSetSpacingFontSizeFamily(paragraph, "preserve", size, "Times New Roman");
                    }
                   // writeDump(var=XMLUtils.marshalToString(dataText), abort=true);
                    bmParentList.addAll(bookmarkIndex+1, dataText);

                    return;
        }
    }


I hope all this makes sense and I'm doing something that makes sense and I'm not approaching this completely backwards.

Thanks for any help in advance!

Re: xhtml fragments into existing word document

PostPosted: Sat May 24, 2014 7:05 am
by jason
So what is appended at the bookmark - something or nothing? Would be helpful to see some XML

Re: xhtml fragments into existing word document

PostPosted: Tue May 27, 2014 1:36 am
by jspriggs
Everything gets appended at the bookmark, but it doesn't indent properly. For example, there's a response with an unordered list and the list resets it's indentation and is back to the left.

Here's a sample of the generated output from the converted html. The whole doc is far too long to paste here.

Code: Select all
<w:p>
  <w:pPr>
    <w:spacing w:after="0"/>
    <w:ind w:left="0"/>
    <w:jc w:val="left"/>
  </w:pPr>
  <w:r>
    <w:rPr>
      <w:rFonts w:ascii="Times New Roman"/>
      <w:b w:val="false"/>
      <w:i w:val="false"/>
      <w:color w:val="000000"/>
      <w:sz w:val="24"/>
    </w:rPr>
    <w:t xml:space="preserve">1. </w:t>
  </w:r>
</w:p>
<w:p>
  <w:pPr>
    <w:numPr>
      <w:ilvl w:val="0"/>
      <w:numId w:val="43"/>
    </w:numPr>
    <w:spacing w:after="0"/>
    <w:jc w:val="left"/>
  </w:pPr>
  <w:r>
    <w:rPr>
      <w:rFonts w:ascii="Times New Roman"/>
      <w:b w:val="false"/>
      <w:i w:val="false"/>
      <w:color w:val="000000"/>
      <w:sz w:val="24"/>
    </w:rPr>
    <w:t xml:space="preserve">Section 1</w:t>
  </w:r>
</w:p>
<w:p>
  <w:pPr>
    <w:numPr>
      <w:ilvl w:val="0"/>
      <w:numId w:val="43"/>
    </w:numPr>
    <w:spacing w:after="0"/>
    <w:jc w:val="left"/>
  </w:pPr>
  <w:r>
    <w:rPr>
      <w:rFonts w:ascii="Times New Roman"/>
      <w:b w:val="false"/>
      <w:i w:val="false"/>
      <w:color w:val="000000"/>
      <w:sz w:val="24"/>
    </w:rPr>
    <w:t xml:space="preserve">Section 2</w:t>
  </w:r>
</w:p>



It looks like what's problematic is that when the xmlimporter runs, it's not maintaining any ids for referencing the paragraph positions in reference to each other. I don't see any rsidP, rsidR or rsidRPr attributes. Is the importer supposed to create those links?

Re: xhtml fragments into existing word document

PostPosted: Tue May 27, 2014 8:00 am
by jason
jspriggs wrote:rsidP, rsidR or rsidRPr


Word inserts those to assist with differencing/change tracking. They are of little value and so docx4j's code never inserts them, though you can create or manipulate them if you wish.

In the XML you posted, the paragraphs containing "Section 1" and "Section 2" both have list properties:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
    <w:numPr>
      <w:ilvl w:val="0"/>
      <w:numId w:val="43"/>
    </w:numPr>
 
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


The numbering definitions part ought to contain a definition for list 43; I guess its definition is not what you were expecting!

So the question is why? Are you appending the paragraph to the same pkg object that you passed into XHTMLImporter?

If yes, you may wish to post a small snippet of your XHTML: just the XHTML corresponding to the "Section 1" paragraph (and its ancestor tags), plus relevant CSS. I'll then run this through XHTMLImporter to see what happens.

Re: xhtml fragments into existing word document

PostPosted: Wed May 28, 2014 12:39 am
by jspriggs
I think I understand part of my problem more now, it's that I have some funky html to begin with that isn't going to make sense translated to word. So I think what I need to do is create a numbered list and take each response individually to convert to word via XHTMLImporterImpl.

Here's my other issue though, the places some of these responses get dropped into are going to be parts of existing lists. so for instance:

Code: Select all
<w:p w:rsidRDefault="005A7EEF" w:rsidP="00DB0D14" w:rsidR="00897AD3" w:rsidRPr="00897AD3">
  <w:pPr>
    <w:widowControl/>
    <w:numPr>
      <w:ilvl w:val="1"/>
      <w:numId w:val="5"/>
    </w:numPr>
    <w:autoSpaceDE/>
    <w:autoSpaceDN/>
    <w:adjustRightInd/>
  </w:pPr>
  <w:r w:rsidRPr="005A7EEF">
    <w:rPr>
      <w:rFonts w:hAnsi="Times New Roman" w:ascii="Times New Roman"/>
      <w:sz w:val="24"/>
    </w:rPr>
    <w:t xml:space="preserve">blah blah question text</w:t>
  </w:r>
  <w:r w:rsidRPr="005A7EEF">
    <w:rPr>
      <w:rFonts w:hAnsi="Times New Roman" w:ascii="Times New Roman"/>
      <w:sz w:val="24"/>
      <w:u w:val="single"/>
    </w:rPr>
    <w:t>target</w:t>
  </w:r>
  <w:r w:rsidRPr="005A7EEF">
    <w:rPr>
      <w:rFonts w:hAnsi="Times New Roman" w:ascii="Times New Roman"/>
      <w:sz w:val="24"/>
    </w:rPr>
    <w:t xml:space="preserve">blah blah question text </w:t>
  </w:r>
  <w:r w:rsidRPr="005A7EEF">
    <w:rPr>
      <w:rFonts w:hAnsi="Times New Roman" w:ascii="Times New Roman"/>
      <w:sz w:val="24"/>
      <w:u w:val="single"/>
    </w:rPr>
    <w:t>actual</w:t>
  </w:r>
  <w:r w:rsidRPr="005A7EEF">
    <w:rPr>
      <w:rFonts w:hAnsi="Times New Roman" w:ascii="Times New Roman"/>
      <w:sz w:val="24"/>
    </w:rPr>
    <w:t xml:space="preserve"> blah blah question text </w:t>
  </w:r>
  <w:r w:rsidRPr="005A7EEF">
    <w:rPr>
      <w:rFonts w:hAnsi="Times New Roman" w:ascii="Times New Roman"/>
      <w:b/>
      <w:sz w:val="24"/>
      <w:u w:val="single"/>
    </w:rPr>
    <w:t>See Appendix for a sample</w:t>
  </w:r>
  <w:r w:rsidRPr="005A7EEF">
    <w:rPr>
      <w:rFonts w:hAnsi="Times New Roman" w:ascii="Times New Roman"/>
      <w:sz w:val="24"/>
    </w:rPr>
    <w:t>.</w:t>
  </w:r>
  <w:bookmarkStart w:id="0" w:name="responseGoesAfterBookmark"/>
  <w:bookmarkStart w:id="1" w:name="_GoBack"/>
  <w:bookmarkEnd w:id="0"/>
  <w:bookmarkEnd w:id="1"/>
</w:p>


That is the xml from the word doc for where I'm trying to drop a set of responses that have html content. So, the problem here is that when I append the new content, the lists are set as level 0, as that's what the xhtml importer is expecting. I'll tinker around and see if there's anyway by wrapping more lists in the html to force the levels to come out right.

Thanks for all the help so far! The support is good and even with issues like this it's easier than forcing a word document out of html.

Re: xhtml fragments into existing word document

PostPosted: Wed May 28, 2014 2:53 am
by jspriggs
so I've been trying a few different things to see what would work best for me. and it looks like the only way I get the numbering/lists to insert with the correct numbers/letters/bullets is if they aren't nested, but then I don't get them to the correct indent level. If I nest them in lists, I can force them into the correct indent level, but then the numbering gets wrong. It will either just use a standard numbered list without breaks/restarts and no bullets/lettering or it just drops all listing numbering totally.

Is there a better way to force an indentation level on a list via CSS or a style or is there something I'm missing on dealing with nested lists?

Re: xhtml fragments into existing word document

PostPosted: Wed May 28, 2014 7:36 pm
by jason
Please try:
1. defining a list style in the target Word document
2. using the corresponding style name in @class on the incoming ol|ul element

Given XHTMLImporterImpl line 1014, this should work provided you have paragraphFormatting option set to CLASS_TO_STYLE_ONLY or CLASS_PLUS_OTHER. The default is FormattingOption.CLASS_PLUS_OTHER

Re indent, except in the CLASS_TO_STYLE_ONLY case, at 2166 there is:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
        if (styleable.getElement()!=null
                        && isListItem(styleable.getElement()) ) {

                /* In Word, indentation is given effect in the following priority:
                 * 1. ad hoc setting (if present)
                 * 2. if specified in the numbering, then that
                 * 3. finally, the paragraph style
                 *
                 * so for IGNORE_CLASS or CLASS_PLUS_OTHER, the way to
                 * honour the CSS is to make an ad hoc setting
                 * (ie pPr.setInd ).
                 *
                 *  But the practical problem is:
                 *  (i)  distinguishing a genuine CSS value from a default.
                 *       Since 0 is the default, we'll ignore that. (Which means
                 *       explicitly setting 0 will not be honoured!)
                 *  (ii) in the CLASS_PLUS_OTHER case, will removeRedundantProperties work
                 *       (using ppr from paragraph style, overridden by numbering)
                 */

               
                // Special handling for indent, since we need to sum values for ancestors
                int totalPadding = 0;
            LengthValue padding = (LengthValue)styleable.getStyle().valueByName(CSSName.PADDING_LEFT);
            totalPadding +=Indent.getTwip(padding.getCSSPrimitiveValue());
           
            LengthValue margin = (LengthValue)styleable.getStyle().valueByName(CSSName.MARGIN_LEFT);
            totalPadding +=Indent.getTwip(margin.getCSSPrimitiveValue());                                      
               
            totalPadding +=listHelper.getAncestorIndentation();
           
                // FS default css is 40px padding per level = 600 twip
            int defaultInd =  600 * listHelper.getDepth();
            if (totalPadding==defaultInd) {
                // we can't tell whether this is just a default, so ignore it; use the numbering setting
                log.debug("explicitly unsetting pPr indent");
                pPr.setInd(null);
            } else {
                pPr.setInd(listHelper.getInd(totalPadding));
            }
               
        }
 
Parsed in 0.017 seconds, using GeSHi 1.0.8.4

Re: xhtml fragments into existing word document

PostPosted: Thu May 29, 2014 12:24 am
by jspriggs
I tried the formatting option route, still having issues. If I go Style only, then I lose the lists altogether. If I go with the other PLUS, then I keep my lists, but I'm still having a small issue with formatting. I've gotten it to the point that it's just that when there are 2 lists in the same html chunk, then it doesn't break the lists correctly. So if I have a ul and an ol, I get a long ul instead of 2 lists that are different. Here's the example:

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <style type="text/css">.toTheLeft{margin-left: 1in;} .olDefaultStyle {list-style-type: decimal;} .ulDefaultStyle {list-style-type: circle;}</style>
    </head>
    <body>
      <ul style="list-style: none;">
        <li>
          <span class="toTheLeft">2. Col. Gentleman's list of heroes</span>
          <ul class="ulDefaultStyle">
            <li>
              <span style="line-height:1.6em">Batman</span>
            </li>
            <li>Green Arrow</li>
            <li>Dirk Gently</li>
            <li>Svlad Chailey</li>
          </ul>
          <p></p>
          <ol class="olDefaultStyle">
            <li>Pringles</li>
            <li>Lays</li>
            <li>Ruffles</li>
          </ol>
        </li>
      </ul>
    </body>
  </html>


And here's what it renders to for word:

Code: Select all
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:ns27="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
  <w:pPr>
    <w:numPr>
      <w:ilvl w:val="0"/>
      <w:numId w:val="44"/>
    </w:numPr>
    <w:spacing w:after="0"/>
    <w:jc w:val="left"/>
  </w:pPr>
  <w:r>
    <w:rPr>
      <w:rFonts w:ascii="Times New Roman"/>
      <w:b w:val="false"/>
      <w:i w:val="false"/>
      <w:color w:val="000000"/>
      <w:sz w:val="24"/>
    </w:rPr>
    <w:t xml:space="preserve">2. Col. Gentleman's list of heroes</w:t>
  </w:r>
  <w:r>
    <w:rPr>
      <w:rFonts w:ascii="Times New Roman"/>
      <w:b w:val="false"/>
      <w:i w:val="false"/>
      <w:color w:val="000000"/>
      <w:sz w:val="24"/>
    </w:rPr>
    <w:t xml:space="preserve">
  </w:t>
</w:r>
</w:p>
  <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:ns27="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
    <w:pPr>
      <w:numPr>
        <w:ilvl w:val="1"/>
        <w:numId w:val="44"/>
      </w:numPr>
      <w:spacing w:after="0"/>
      <w:jc w:val="left"/>
    </w:pPr>
    <w:r>
      <w:rPr>
        <w:rFonts w:ascii="Times New Roman"/>
        <w:b w:val="false"/>
        <w:i w:val="false"/>
        <w:color w:val="000000"/>
        <w:sz w:val="24"/>
      </w:rPr>
      <w:t xml:space="preserve">Batman</w:t>
    </w:r>
  </w:p>
  <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:ns27="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
    <w:pPr>
      <w:numPr>
        <w:ilvl w:val="1"/>
        <w:numId w:val="44"/>
      </w:numPr>
      <w:spacing w:after="0"/>
      <w:jc w:val="left"/>
    </w:pPr>
    <w:r>
      <w:rPr>
        <w:rFonts w:ascii="Times New Roman"/>
        <w:b w:val="false"/>
        <w:i w:val="false"/>
        <w:color w:val="000000"/>
        <w:sz w:val="24"/>
      </w:rPr>
      <w:t xml:space="preserve">Green Arrow</w:t>
    </w:r>
  </w:p>
  <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:ns27="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
    <w:pPr>
      <w:numPr>
        <w:ilvl w:val="1"/>
        <w:numId w:val="44"/>
      </w:numPr>
      <w:spacing w:after="0"/>
      <w:jc w:val="left"/>
    </w:pPr>
    <w:r>
      <w:rPr>
        <w:rFonts w:ascii="Times New Roman"/>
        <w:b w:val="false"/>
        <w:i w:val="false"/>
        <w:color w:val="000000"/>
        <w:sz w:val="24"/>
      </w:rPr>
      <w:t xml:space="preserve">Dirk Gently</w:t>
    </w:r>
  </w:p>
  <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:ns27="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
    <w:pPr>
      <w:numPr>
        <w:ilvl w:val="1"/>
        <w:numId w:val="44"/>
      </w:numPr>
      <w:spacing w:after="0"/>
      <w:jc w:val="left"/>
    </w:pPr>
    <w:r>
      <w:rPr>
        <w:rFonts w:ascii="Times New Roman"/>
        <w:b w:val="false"/>
        <w:i w:val="false"/>
        <w:color w:val="000000"/>
        <w:sz w:val="24"/>
      </w:rPr>
      <w:t xml:space="preserve">Svlad Chailey</w:t>
    </w:r>
  </w:p>
  <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:ns27="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
    <w:pPr>
      <w:spacing w:after="0"/>
      <w:ind w:left="800"/>
      <w:jc w:val="left"/>
    </w:pPr>
  </w:p>
  <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:ns27="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
    <w:pPr>
      <w:numPr>
        <w:ilvl w:val="1"/>
        <w:numId w:val="44"/>
      </w:numPr>
      <w:spacing w:after="0"/>
      <w:jc w:val="left"/>
    </w:pPr>
    <w:r>
      <w:rPr>
        <w:rFonts w:ascii="Times New Roman"/>
        <w:b w:val="false"/>
        <w:i w:val="false"/>
        <w:color w:val="000000"/>
        <w:sz w:val="24"/>
      </w:rPr>
      <w:t xml:space="preserve">Pringles</w:t>
    </w:r>
  </w:p>
  <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:ns27="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
    <w:pPr>
      <w:numPr>
        <w:ilvl w:val="1"/>
        <w:numId w:val="44"/>
      </w:numPr>
      <w:spacing w:after="0"/>
      <w:jc w:val="left"/>
    </w:pPr>
    <w:r>
      <w:rPr>
        <w:rFonts w:ascii="Times New Roman"/>
        <w:b w:val="false"/>
        <w:i w:val="false"/>
        <w:color w:val="000000"/>
        <w:sz w:val="24"/>
      </w:rPr>
      <w:t xml:space="preserve">Lays</w:t>
    </w:r>
  </w:p>
  <w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:ns27="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
    <w:pPr>
      <w:numPr>
        <w:ilvl w:val="1"/>
        <w:numId w:val="44"/>
      </w:numPr>
      <w:spacing w:after="0"/>
      <w:jc w:val="left"/>
    </w:pPr>
    <w:r>
      <w:rPr>
        <w:rFonts w:ascii="Times New Roman"/>
        <w:b w:val="false"/>
        <w:i w:val="false"/>
        <w:color w:val="000000"/>
        <w:sz w:val="24"/>
      </w:rPr>
      <w:t xml:space="preserve">Ruffles</w:t>
    </w:r>
  </w:p>


When you look at the word xml it's generating mostly correctly for me with the exception of the numId element. The first list should be id 44, but starting with Pringles it should switch to a new id, I'd expect 45, but it stays with 44, so it joins to the same list and becomes just a continuation of the previous unordered list.

Any thoughts/suggestions? Sorry if the code is messy, the html is generated by code, I ran both through a formatter, so hopefully they aren't horrible to read.

Re: xhtml fragments into existing word document

PostPosted: Thu May 29, 2014 8:11 am
by jason
Looks like you don't have list mapping set up correctly.

What do the definitions for styles ulDefaultStyle and olDefaultStyle look like (xml) in the style definition part (styles.xml) of your docx?