none
An extra paragraph is added to the selection after manipulation through setSelectedDataAsync coercionType ooxml RRS feed

  • Question

  • Hi,

    We have a strange issue that after changing the markup of a selection a paragraph is always added at the end of the selection even though it's not in our ooxml that we have set through Office.context.document.setSelectedDataAsync with the parameter coercionType set to ooxml. Any idea where this extra paragraph could be comming from and how we can prevent this behaviour?

    Thanks in advance!
    Caroline


    Edit: this is a word app
    • Edited by Caroline2AT Monday, September 29, 2014 4:44 PM
    Monday, September 29, 2014 4:36 PM

All replies

  • Hi Caroline,

    I am failed to rerproduce the issue. Here the test code:

     function setDataFromSelection() {
    
        var newText = "<w:p w:rsidR=\"002E7638\" w:rsidP=\"00963883\" w:rsidRDefault=\"002E7638\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">" +
      "<w:pPr>" +
        "<w:pStyle w:val=\"BodyText\" />" +
     "</w:pPr>" +
      "<w:r>" +
        "<w:t>Hello Word!</w:t>" +
      "</w:r>" +
      "<w:bookmarkStart w:name=\"_GoBack\" w:id=\"0\" />" +
      "<w:bookmarkEnd w:id=\"0\" />" +
    "</w:p>";
    
            // Get the OOXML for the data at the point of insertion
            // and add a table at the beginning of the selection.
            Office.context.document.getSelectedDataAsync(
              Office.CoercionType.Ooxml,
              {
                  valueFormat: Office.ValueFormat.Formatted,
                  filterType: Office.FilterType.All
              },
              function (result) {
                  if (result.status == "succeeded") {
                      // Get the OOXML returned from the getSelectedDataAsync call.
                      var selectedData = result.value.toString();
                      // Define the new table in OOXML.
                      //var newTable = "<!--Details omitted for brevity.-->";
                      // Find the '<w:body>' tag in the returned data—the tag
                      // that represents the body content of the selection, contained
                      // within the main document package part (/word/document.xml)—
                      // and then insert the new table into the OOXML at that point.
                      var newString = selectedData.replace(
                        "<w:body>",
                        //"<w:body>" + newTable,
                        "<w:body>" + newText,
                        "gi");
                      // Insert the data back into the document with the table added.
                      Office.context.document.setSelectedDataAsync(
                        newString,
                        { coercionType: Office.CoercionType.Ooxml },
                        function (rs) {
                            if (result.status == "succeeded") {
    
                            }
                        });
                  }
              });
    
         
    
    
        }

    Screenshot:

    Would you mind sharing a code sample to help us to reproduce the issue? I also suggest that you use the Open XML SDK productivity tools to check the difference between the file changed before and after.

    Best regards

    Fei

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, October 3, 2014 5:34 AM
    Moderator
  • Hi Fei,

    Thank you for your elaborate answer!
    It looks like the behaviour is caused by the CommentReference we added.

    However if I add a comment through the Word API and look at the XML from the getSelectedDataAsync, I don't see a difference that would explain the added paragraph.

    Caroline

    Monday, October 6, 2014 11:34 AM
  • Hi Caroline,

    Thanks for your detail information.

    >>It looks like the behaviour is caused by the CommentReference we added.

    However if I add a comment through the Word API and look at the XML from the getSelectedDataAsync, I don't see a difference that would explain the added paragraph.<<

    I am still failed to reproduce the issue. The text didn't show when I insert the OOML to the document which contained the comment. Here is the XML I inserted for your reference:

        <w:commentRangeStart w:id="1"/>
                <w:r>
                  <w:t>Hello Word!</w:t>
                </w:r>
                <w:commentRangeEnd w:id="1"/>
                <w:r>
                  <w:rPr>
                    <w:rStyle w:val="CommentReference"/>
                  </w:rPr>
                  <w:commentReference w:id="1"/>
                </w:r>
              </w:p>

    As far as I know, the comment contain two part. The first part is XML in document.xml and the second part is coment self in comments.xml. When we insert the XML which contained first part, the document colund't analyse xml correctly. That may be the reason why it add extra paragraph.

    I suggest that you check the XML after you insert the XML to see whether it is as expected.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 8, 2014 7:30 AM
    Moderator
  • Hi,

    I have created a sample to reproduce the issue. This example inserts a static text with a comment on it. The example is created by manipulating the XML that is retrieved with GetSelectedDataAsync. When the run with the CommentReference is removed, no new paragraph is created (but no comment is added to the selection).

    https://onedrive.live.com/redir?resid=B8B15F07FA9B5D91!8270&authkey=!AKxC11uek-hbnx4&ithint=file%2czip


    Best regards,

    Bart Kapitein


    Thursday, October 30, 2014 8:23 AM