html ordered list remains on 1 when inserted in document

Last post 06-17-2008, 4:33 AM by alexey.noskov. 7 replies.
Sort Posts: Previous Next
  •  06-11-2008, 3:33 AM 130892

    html ordered list remains on 1 when inserted in document

    Hello,

     

    when trying to insert html code into a document the ordered list in the html is inserted but always remains on '1' for every item. Is this a bug or?

    Thx Mike

    the code used for insert is:

    DocumentBuilder builder = new DocumentBuilder(doc);

    builder.moveToMergeField(strFieldname);

    builder.insertHtml(value); (value= <body><ol start="1"><li>aaaaaaa</li><li>bbbbbbb</li><li>ccccc</li></ol><p /></body>)

    Filed under: html ordered list doc
     
  •  06-11-2008, 3:55 AM 130895 in reply to 130892

    Re: html ordered list remains on 1 when inserted in document

    Hello!

     

    Thank you for your inquiry.

     

    I tried inserting this HTML fragment and the list is numbered as expected: 1, 2, 3. Maybe this is specific to your document or supplementary code. Please ensure you are using the latest version of Aspose.Words and provide more information to reproduce the problem.

     

    Regards,
    Viktor Sazhaev
    Software Engineer, Aspose Auckland Team
     
  •  06-11-2008, 9:10 AM 130942 in reply to 130895

    Re: html ordered list remains on 1 when inserted in document

    Attachment: Present (inaccessible)

    Done some more research...the html is first copied to a tmp doc and then the temp doc is inserted in the main doc using the KEEP_SOURCE_FORMATTING. When I look at the tmp-doc, the list is well created following 1,2,3... When i look at the main doc, i see that every item in the list also has a new created style(standard_1,standard_2,standard_3,etc). I putted the tmp_doc, and final doc in attachment....

    Thx,

    Michael

     
  •  06-11-2008, 10:40 AM 130952 in reply to 130942

    Re: html ordered list remains on 1 when inserted in document

    Hello again.

     

    I looked inside the Output.doc (by converting to WordprocessingML) and figured out that all four list paragraphs belong to different lists. Each has “restart from 1” property. Items that you expect to be 1, 2, 3 should be the one list. I cannot see how you are obtaining this. Please provide a code snippet showing what you are doing with the documents.

     

    Regards,
    Viktor Sazhaev
    Software Engineer, Aspose Auckland Team
     
  •  06-11-2008, 11:03 AM 130959 in reply to 130942

    Re: html ordered list remains on 1 when inserted in document

    Hi

     

    Thanks for your inquiry. I think that you are using InsertDocumentAtMergeField method. Right? If so you can try modifying your method as the following.

     

    public static void InsertDocumentAtMergeField(String mergeFieldName, Document dstDoc, Document srcDoc) throws Exception

    {

        //Create DocumentBuilder

        DocumentBuilder builder = new DocumentBuilder(dstDoc);

        //Move cursor to bookmark and insert paragraph break

        builder.moveToMergeField(mergeFieldName);

        builder.writeln();

        //Content of srcdoc will be inserted after this node

        Node insertAfterNode = builder.getCurrentParagraph().getPreviousSibling();

        //Content of first paragraph of srcDoc will be apended to this parafraph

        Paragraph insertAfterParagraph = (Paragraph)insertAfterNode;

        //Content of last paragraph of srcDoc will be apended to this parafraph

        Paragraph insertBeforeParagraph = builder.getCurrentParagraph();

        //We will be inserting into the parent of the destination paragraph.

        CompositeNode dstStory = insertAfterNode.getParentNode();

        //Create temporary list

        List srcTmpList = null;

        List dstTmpList = null;

        //Remove empty paragraphs from the end of document

        while (!srcDoc.getLastSection().getBody().getLastParagraph().hasChildNodes())

        {

            srcDoc.getLastSection().getBody().getLastParagraph().remove();

        }

        //Loop through all sections in the source document.

        int sectCount = srcDoc.getSections().getCount();

        for(int sectIndex=0; sectIndex<sectCount; sectIndex++)

        {

            Section srcSection = srcDoc.getSections().get(sectIndex);

            //Loop through all block level nodes (paragraphs and tables) in the body of the section.

            int nodeCount = srcSection.getBody().getChildNodes().getCount();

            for(int nodeIndex=0; nodeIndex<nodeCount; nodeIndex++)

            {

                Node srcNode = srcSection.getBody().getChildNodes().get(nodeIndex);

                //Do not insert node if it is a last empty paragarph in the section.

                Paragraph para = (Paragraph)srcNode ;

                if ((para != null) && para.isEndOfSection() && (!para.hasChildNodes()))

                {

                    break;

                }

     

                //If current paragraph is first paragraph of srcDoc

                //then appent its content to insertAfterParagraph

                if (para.equals(srcDoc.getFirstSection().getBody().getFirstParagraph()) && insertAfterParagraph.hasChildNodes())

                {

                    int firstParaChildCount = para.getChildNodes().getCount();

                    for(int childIndex = 0; childIndex<firstParaChildCount; childIndex++)

                    {

                        Node node = para.getChildNodes().get(childIndex);

                        Node dstNode = dstDoc.importNode(node, true, ImportFormatMode.KEEP_SOURCE_FORMATTING);

                        insertAfterParagraph.appendChild(dstNode);

                    }

     

                    //If subdocument contains only one paragraph

                    //then copy content of insertBeforeParagraph to insertAfterParagraph

                    //and remove insertBeforeParagraph

                    if (srcDoc.getFirstSection().getBody().getFirstParagraph().equals(srcDoc.getLastSection().getBody().getLastParagraph()))

                    {

                        while (insertBeforeParagraph.hasChildNodes())

                        {

                            insertAfterParagraph.appendChild(insertBeforeParagraph.getFirstChild());

                        }

                        insertBeforeParagraph.remove();

                    }

                }

                //If current paragraph is last paragraph of srcDoc

                //then appent its content to insertBeforeParagraph

                else if (para.equals(srcDoc.getLastSection().getBody().getLastParagraph()) &&  insertBeforeParagraph.hasChildNodes())

                {

                    Node previouseNode = null;

                    int firstParaChildCount = para.getChildNodes().getCount();

                    for(int childIndex = 0; childIndex<firstParaChildCount; childIndex++)

                    {

                        Node node = para.getChildNodes().get(childIndex);

                        Node dstNode = dstDoc.importNode(node, true, ImportFormatMode.KEEP_SOURCE_FORMATTING);

                        if (previouseNode == null)

                        {

                            insertBeforeParagraph.insertBefore(dstNode, insertBeforeParagraph.getFirstChild());

                        }

                        else

                        {

                            insertBeforeParagraph.insertAfter(dstNode, previouseNode);

                        }

                        previouseNode = dstNode;

                    }

                }

                else

                {

                    //This creates a clone of the node, suitable for insertion into the destination document.

                    Node newNode = dstDoc.importNode(srcNode, true, ImportFormatMode.KEEP_SOURCE_FORMATTING);

                    if(srcNode.getNodeType() == NodeType.PARAGRAPH)

                    {

                         Paragraph srcTmpPar = (Paragraph)srcNode;

                         Paragraph dstTmpPar = (Paragraph)newNode;

                          if(srcTmpPar.getListFormat().getList()==srcTmpList)

                         {

                              dstTmpPar.getListFormat().setList(dstTmpList);

                         }

                         else

                         {

                             srcTmpList = srcTmpPar.getListFormat().getList();

                             dstTmpList = dstTmpPar.getListFormat().getList();

                         }

                    }

                    //Insert new node after the reference node.

                    dstStory.insertAfter(newNode, insertAfterNode);

                    insertAfterNode = newNode;

                }

     

            }

            if(!insertAfterParagraph.hasChildNodes())

                insertAfterParagraph.remove();

            if(!insertBeforeParagraph.hasChildNodes())

                insertBeforeParagraph.remove();

     

        }

    }

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  06-12-2008, 6:50 AM 131082 in reply to 130959

    Re: html ordered list remains on 1 when inserted in document

    Thanks a lot guys...problem was the InsertDocumentAtMergeField method and is solved now...your support is really great!!

    Many many thanks again,

    Greetz

    Michael

     
  •  06-17-2008, 3:39 AM 131562 in reply to 131082

    Re: html ordered list remains on 1 when inserted in document

    Attachment: Present (inaccessible)

    Hi there,

    seems that the solution provided last time implicates a new little problem... The first paragraph lost its style. Looks a lot like one of my other issues I had before with this same method.

    I added an example in attachment.

     

    Thx,

    Michael

     
  •  06-17-2008, 4:33 AM 131576 in reply to 131562

    Re: html ordered list remains on 1 when inserted in document

    Hi

     

    Thanks for your inquiry. I tested this on my side and it seems that all works fine. Here is output that I got.

     

    1           Plaats

    Tussen de atlaspunten ATLAS1 en ATLAS2, meer speciaal «INSERTARRAY(getPlaatsBepalingTaludverste»

     

    Here is my code:

     

    Document tmpDoc = new Document("source.doc");

    Document doc = new Document("ToBeInserted.doc");

    InsertDocumentAtMergeField(tmpDoc.getMailMerge().getFieldNames()[2], tmpDoc, doc);

    tmpDoc.save("out.doc");

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
View as RSS news feed in XML