I'm developing a .NET C# app that needs to create a Word document, inserting fragments of RTF text which are stored in a database. Does anyone know if it is possible and how this is done using OpenXml (or COM interop)?
I don't need to convert one complete RTF file into a Word document. I need to programatically create a Word document and add pieces of RTF text in different places in the word document using C#.
Best Answer
You can import external content via the altChunk anchor. The altChunk anchor defines a place within a word document to insert external content such as RTF, HTML, XML, ...
For more information about the altChunk anchor please refer to the following MSDN article.
The following code shows how to insert a chunk of RTF into a word document using the OpenXML SDK:
AlternativeFormatImportPart
chunk with a unique chunk ID.MemoryStream
here).AltChunk
with the same ID used to create theAlternativeFormatImportPart
..