locked
setSelectedDataAsync returned a docx with different font type RRS feed

  • Question

  • Hope I can find some help from here. I have bee searching online all day along but found little helpful info. 

    I was using the setSelectedDataAsync method to convert a plain ooxml (exported from Word) to a docx using Office Task pane. Nearly all styles were correctly returned but not the the font type. The font type in the ooxml somehow was ignored. Instead it uses the default font type in the current Word app. Any thoughts why this happened. Appreciate any help. 

    Office.context.document.setSelectedDataAsync(ooxml, {coercionType:'ooxml'},
                function (result) {
                    if (result.status == "failed") {
                        app.showNotification('Error:', result.error.message);
                    } else {
                        app.showNotification('yay!!');
                    }
                }

    Alex

    Monday, January 26, 2015 10:03 PM

Answers

  • Hi Alex,

    According to the description, you want to set the select data however the font was ignored.

    I am trying to reproduce the issue however failed. Here is the code that write the "Hello Word" with Aharoni font style:

    function setDataFromSelection() {
    
            var newText = "<w:p w:rsidRPr='001C21EB' w:rsidR='00050583' w:rsidP='00963883' w:rsidRDefault='001C21EB' xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>" +
      "<w:pPr>" +
        "<w:pStyle w:val='BodyText' />" +
        "<w:rPr>" +
          "<w:rFonts w:ascii='Aharoni' w:hAnsi='Aharoni' w:cs='Aharoni' />" +
        "</w:rPr>" +
      "</w:pPr>" +
      "<w:bookmarkStart w:name='_GoBack' w:id='0' />" +
      "<w:r w:rsidRPr='001C21EB'>" +
        "<w:rPr>" +
          "<w:rFonts w:ascii='Aharoni' w:hAnsi='Aharoni' w:cs='Aharoni' />" +
        "</w:rPr>" +
        "<w:t> Hello Word! </w:t>" +
      "</w:r>" +
      "<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") {
    
                            }
                        });
                  }
              });
    
    
    
    
        }

    Based on my standing, this issue would occur if the fonts didn't install on the computer, would you mind check whether the font installed?

    Regards & Fei



    Based on my understanding, if the font doesn't


    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.

    Thursday, January 29, 2015 2:27 AM
  • Hi dugwsl,

    >>I found out that if the docx uses any theme font, the API is going to ignore it during conversion. <<

    Base on the test, the code also works well when I apply the themes.  I suggest that you check whether the font was install on the Windows.

    Also you can try the code above to see whether it works.

    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.

    • Marked as answer by dugwsl Tuesday, February 10, 2015 6:17 PM
    Monday, February 9, 2015 6:16 AM

All replies

  • Hi Alex,

    According to the description, you want to set the select data however the font was ignored.

    I am trying to reproduce the issue however failed. Here is the code that write the "Hello Word" with Aharoni font style:

    function setDataFromSelection() {
    
            var newText = "<w:p w:rsidRPr='001C21EB' w:rsidR='00050583' w:rsidP='00963883' w:rsidRDefault='001C21EB' xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>" +
      "<w:pPr>" +
        "<w:pStyle w:val='BodyText' />" +
        "<w:rPr>" +
          "<w:rFonts w:ascii='Aharoni' w:hAnsi='Aharoni' w:cs='Aharoni' />" +
        "</w:rPr>" +
      "</w:pPr>" +
      "<w:bookmarkStart w:name='_GoBack' w:id='0' />" +
      "<w:r w:rsidRPr='001C21EB'>" +
        "<w:rPr>" +
          "<w:rFonts w:ascii='Aharoni' w:hAnsi='Aharoni' w:cs='Aharoni' />" +
        "</w:rPr>" +
        "<w:t> Hello Word! </w:t>" +
      "</w:r>" +
      "<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") {
    
                            }
                        });
                  }
              });
    
    
    
    
        }

    Based on my standing, this issue would occur if the fonts didn't install on the computer, would you mind check whether the font installed?

    Regards & Fei



    Based on my understanding, if the font doesn't


    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.

    Thursday, January 29, 2015 2:27 AM
  • Thanks for your reply. I found out that if the docx uses any theme font, the API is going to ignore it during conversion. I'll appreciate if you can look into the issue. 
    • Edited by dugwsl Friday, February 6, 2015 5:29 PM
    Friday, February 6, 2015 5:25 PM
  • Hi dugwsl,

    >>I found out that if the docx uses any theme font, the API is going to ignore it during conversion. <<

    Base on the test, the code also works well when I apply the themes.  I suggest that you check whether the font was install on the Windows.

    Also you can try the code above to see whether it works.

    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.

    • Marked as answer by dugwsl Tuesday, February 10, 2015 6:17 PM
    Monday, February 9, 2015 6:16 AM
  •  //     var options = {
                //         valueFormat: "unformatted",
                //         filterType: "all"
                //     };


                //Office.context.documentgetslectedAsync('hello',options, function(asyncResult1) {

    There is optinal parameter for getting the unformatted or formated XML,i.e you must pass above optional value.......

     serach in JavascriptAPI for valueFormat: "unformatted,u must get better understnadin

     var options = {
                //         valueFormat: "unformatted",
                //         filterType: "all"
                //     };

    Monday, February 9, 2015 7:17 PM
  • Thanks Fei. Is there a way i can upload an ooxml for you to test at your end? the ooxml is too big to paste it here. 
    Tuesday, February 10, 2015 6:21 PM
  • Hi dugws,

    Thanks Fei. Is there a way i can upload an ooxml for you to test at your end? the ooxml is too big to paste it here. 
    Yes, you can upload it via OneDrive and please remove the sensitive information before you uploading.

    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, February 11, 2015 8:52 AM
  • Fei, here is the link to get the file - https://onedrive.live.com/redir?resid=7B34C24E6020F0D3%21122 

    it's an ooxml exported via "Export as open XML" from Word. The xml can be opened in Word without loosing any styling, but when it's transformed using the JavaScript API, the font and some other styles were lost. The font which was ignored is a theme font (Arial (Body)) was defaulted to Calibri during transformation. I'll appreciate if you can spend some time looking into the issue. Thanks for your help, 

    Alex


    • Edited by dugwsl Wednesday, February 11, 2015 3:49 PM
    Wednesday, February 11, 2015 3:23 PM