none
Reading HTML tag in Content Controls RRS feed

  • Question

  • Hi All,

    I have build an application where i dynamically generate word document using predefined Templates. I am using Open XML. SO i generate XML programmatically and associate it with WORD 2010.

    I am trying to generalize my templates. What i need is. I have a Rich/Plain Content Control. Its a huge text which varies in style(like bold , italic) in different places depending on condition chosen from interface. I tried putting HTML tag in my XML element of this text but it didnt worked.

    e.g 

    <SampleText> MSDN is the <b>greatest</b> resource of Q</SampleText>

    SampleText is mapped to Rich Context Control in Template word. 

    ANy suggestion i can handle the HTML style in my Content in Word.


    Nidhi Sharepoint Developer


    • Edited by QwertyLady Tuesday, May 13, 2014 7:15 PM
    Tuesday, May 13, 2014 4:02 PM

Answers

All replies

  • Hi,

    Based on the description, you want to create a rich content control and set its style like them show as in html. As far as I know, the child element of rich content control is different with HTML tag, the rich content control can’t represent the html tag. We can create a rich content control in word manually and open it with Open XML productivity tools like below:


    If I you want to apply the style for rich content control, you need to analysis the HTML tag and translate it to the Open XML format like figure above.

    Hope it is helpful.

    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, May 14, 2014 9:37 AM
    Moderator
  • Hey Fei. Thanks for such a descriptive response. But my requirement varies. Sorry for my description.

    Actually what i want is have a Rich Control. Infact i can place any Content Control. 

    Now The XML which i have linked with my document has element called <ModifiedComments>. The content in it can be

    say "I have a great lake view" or may be "I have a great lake view". SO the style of the text can vary. 

    In XML the style i put at generation time gets lost. So  now i need help on how to use Control or any other way of displaying my text in XML in Word with it style.

    I tried putting HTML Tag like "I have a <b>great lake</b> view" in XML element . But then it is not displaying anything in document at time of word generation.

    Thanks in advance for all effort.


    Nidhi Sharepoint Developer

    Wednesday, May 14, 2014 2:02 PM
  • Hi Nidhi

    I agree with Fei Xue.

    A RichText content control knows nothing about HTML. Indeed, Word doesn't use HTML natively, a converter is required. Word's converters trigger only when opening a file or pasting information from the Clipboard. Neither of these will function, of course, working with Open XML as they require the application.

    You could TRY incorporating the text as an AltChunk. AltChunk does support HTML file format and when Word opens the document the converter will trigger.

    If that doesn't work, however, then you need to make your own conversion of the HTML into valid WordOpenXML - there are no shortcuts available for this.

    See:
    http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.altchunk(v=office.14).aspx
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/674070e4-baa5-45ea-b537-527bae150e9c/inserting-plain-text-into-content-controls-in-word-using-altchunk-format-problem?forum=oxmlsdk
    http://openxmlaltchunk.codeplex.com/


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, May 14, 2014 2:44 PM
    Moderator