Shan Plourde
Shan Plourde

Reputation: 8726

Office 2013 JavaScript API for Word - Content Control questions

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 http://social.msdn.microsoft.com/Forums/en-US/appsforoffice/thread/8c4809c7-743c-4388-aef0-bc6a6855c882. 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 at http://msdn.microsoft.com/en-us/library/fp142295.aspx, but I'm unsure how I can do this still, or if it's feasible.

Thanks

Upvotes: 0

Views: 1985

Answers (1)

Nils
Nils

Reputation: 987

though I have not tried this with JS - it should be possible nontheless.

Try adding a altChunk Element, it can contain other open xml or html. I have used it a few times with success.

a few links on the issue: http://blogs.msdn.com/b/brian_jones/archive/2008/12/08/the-easy-way-to-assemble-multiple-word-documents.aspx http://blogs.msdn.com/b/ericwhite/archive/2008/10/27/how-to-use-altchunk-for-document-assembly.aspx

U should however try to use "strict"-xml - otherwise the above might not be possible.

I just found this example (sry it's german, but there should be an english version somewhere as well). In which coercionType is used like this:

    Office.context.document.setSelectedDataAsync(
      booksToRead,
      { coercionType: Office.CoercionType.Html },
      function (result) {
    // Access the results, if necessary.
    });

This might do the trick as well.

Upvotes: 1

Related Questions