none
viewing rich text content from a word document project RRS feed

  • Question

  • I have rich text data saved in SQL in a field type nvarchar(max), see sample content below.

    I am trying to pull this data into a visual studio 2010 word document project, but the the text is not coming in the proper format even if I set the data type of the field in the project data sources to be rich text.

     

     OUTPUT:

     

    DATA in SQL:

    {\rtf1\deff0{\fonttbl{\f0 Times New Roman;}}{\colortbl\red0\green0\blue0 ;\red0\green0\blue255 ;}{\*\listtable {\list\listtemplateid-1\listhybrid{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat1{\leveltext\leveltemplateid75266416 \'02\'00.;}{\levelnumbers\'01;}\levellegal0\levelnorestart0\cf0\fi-360\li720\lin720}{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat1{\leveltext\leveltemplateid960614247 \'02\'01.;}{\levelnumbers\'01;}\levellegal0\levelnorestart0\cf0\fi-360\li1440\lin1440}{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat1{\leveltext\leveltemplateid645492893 \'02\'02.;}{\levelnumbers\'01;}\levellegal0\levelnorestart0\cf0\fi-360\li2160\lin2160}{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat1{\leveltext\leveltemplateid1294513133 \'02\'03.;}{\levelnumbers\'01;}\levellegal0\levelnorestart0\cf0\fi-360\li2880\lin2880}{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat1{\leveltext\leveltemplateid453938919 \'02\'04.;}{\levelnumbers\'01;}\levellegal0\levelnorestart0\cf0\fi-360\li3600\lin3600}{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat1{\leveltext\leveltemplateid2028470431 \'02\'05.;}{\levelnumbers\'01;}\levellegal0\levelnorestart0\cf0\fi-360\li4320\lin4320}{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat1{\leveltext\leveltemplateid173129563 \'02\'06.;}{\levelnumbers\'01;}\levellegal0\levelnorestart0\cf0\fi-360\li5040\lin5040}{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat1{\leveltext\leveltemplateid931962313 \'02\'07.;}{\levelnumbers\'01;}\levellegal0\levelnorestart0\cf0\fi-360\li5760\lin5760}{\listlevel\levelnfc0\levelnfcn0\leveljc0\leveljcn0\levelfollow0\levelstartat1{\leveltext\leveltemplateid1075949278 \'02\'08.;}{\levelnumbers\'01;}\levellegal0\levelnorestart0\cf0\fi-360\li6480\lin6480}{\listname ;}\listid450374152}}{\*\listoverridetable {\listoverride\listid450374152\listoverridecount0\ls1}}{\stylesheet {\ql\cf0 Normal;}{\*\cs1\cf0 Default Paragraph Font;}{\*\cs2\sbasedon1\cf0 Line Number;}{\*\cs3\ul\cf1 Hyperlink;}}\sectd{\listtext\pard 1.\tab }\pard\plain\ilvl0\ls1\ql\fi-360\li720\lin720{\cf0 This is a test}\par{\listtext\pard 2.\tab }\pard\plain\ilvl0\ls1\ql\fi-360\li720\lin720{\b\i\cf0 this is line 2}\b\i\par}

      

     



    • Edited by ckchouk Thursday, December 22, 2011 5:10 PM
    Thursday, December 22, 2011 5:07 PM

Answers

  • Hi "ck"

    Rich text file format is not a "native" Word format. A converter is required in order to place RTF text into a Word document with its formatting. This means you either have to save this RTF to a file and insert that file into a document, or you have to place it on the Clipboard and paste it into the document.

    The other possibility would be to "transform" the RTF into Word Open XML. That's now the standard for Word. Valid Word Open XML can be "streamed" into a Word document using the InsertXML method. You can find more information about this at OpenXMLDeveloper.org


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Bruce Song Tuesday, December 27, 2011 6:59 AM
    • Marked as answer by Bruce Song Wednesday, January 4, 2012 8:16 AM
    Thursday, December 22, 2011 5:39 PM
    Moderator

All replies

  • Hi "ck"

    Rich text file format is not a "native" Word format. A converter is required in order to place RTF text into a Word document with its formatting. This means you either have to save this RTF to a file and insert that file into a document, or you have to place it on the Clipboard and paste it into the document.

    The other possibility would be to "transform" the RTF into Word Open XML. That's now the standard for Word. Valid Word Open XML can be "streamed" into a Word document using the InsertXML method. You can find more information about this at OpenXMLDeveloper.org


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Bruce Song Tuesday, December 27, 2011 6:59 AM
    • Marked as answer by Bruce Song Wednesday, January 4, 2012 8:16 AM
    Thursday, December 22, 2011 5:39 PM
    Moderator
  • Thank you Cindy!

    Monday, December 26, 2011 3:40 PM