none
Office 2013 JavaScript API for Word - Content Control questions RRS feed

  • Question

  • Hello, is it possible to insert a content control into a Word document, then, get some sort of handle or context to the content control, and then insert HTML into it? 

    Essentially, the scenario that I am trying to create with the Office JavaScript API is to, upon the user's request, insert a rich text content control, and then populate it with HTML. 

    I am able to insert the content control from the JavaScript API using the approach suggested at social.msdn.microsoft.com/Forums/en-US/appsforoffice/thread/dd147dab-bff9-490b-9063-c4fc72f0f6ca . It requires a coercionType of ooxml. However, the content that I wish to populate with the ooxml is HTML based. So when I try to insert a content control with the following ooxml:

    ...Boiler ooxml to create content control...

    <w:r><w:t><h1>Test header</h1><h2>Test subheader</h2><p>Test paragraph text</p></w:t></w:r>

    The insert attempt fails. I'm assuming that's because you can't mix ooxml and html when inserting this into the document with a coercionType of ooxml. 

    Since this ooxml approach is the only way you can insert a content control, how can I then set the content control with HTML text? I have looked over the Document object help content, but I'm unsure how I can do this still, or if it's feasible. 

    Thanks

    Shan

    Monday, April 15, 2013 1:19 PM

All replies

  • I'm not able to provide links in my questions at this time, since the forum software says that I haven't yet been authorized or something like that. 
    Monday, April 15, 2013 1:20 PM
  • As suggested in the post you linked...what if you would try to manually insert the content control and write some html into it. Then select this control and call getDataAsync, to see how it is stored. Then recreate this with your code and your content.

    Then again you could also craeate a web service, whith which you would open a rich text control, set the html to it, then read the rtf from it, and set that as text.


    Anze Javornik

    Monday, April 15, 2013 5:53 PM
  • As suggested in the post you linked...what if you would try to manually insert the content control and write some html into it. Then select this control and call getDataAsync, to see how it is stored. Then recreate this with your code and your content.

    Then again you could also craeate a web service, whith which you would open a rich text control, set the html to it, then read the rtf from it, and set that as text.


    Anze Javornik

    I can manually insert the content control, then write some html into it. And then I can use getDataAnync to see how it is stored. In fact I've inspected this already with the OpenXML SDK Productivity tool...The challenge is that, this is for a dynamic content solution - the HTML can be anything in our content data model. Since Office supports coercion type HTML, I don't think that I need to do manually create my own HTML to OOXML converter. 

    My goal is to integrate this with a web service that will return HTML to the task pane. Then, with the Office JavaScript API, I will add a rich text content control (using OOXML coercion type, since this is the only approach supported to add a content control). Then, if this is possible, access the newly added rich text content control, and append to it HTML (using coercion type HTML so that Word's built in HTML to OOXML converter does its thing) to the starting <w:r> within the content control. 

    If that's not feasible, we use Aspose.Words server side. Their model supports the model of populating a content control with HTML, and then exporting that content control to OOXML. So I could use a solution that includes Aspose.Words server side, which always returns the OOXML for the content control. But I was hoping that I could avoid Aspose.Words in the solution, to reduce the payload and assumingly scale better. But I guess I should explore all options.

    Monday, April 15, 2013 6:41 PM
  • Hi Shan, did you ever finalize this?  What was the solution?
    Thursday, March 17, 2016 8:58 AM