You just need to create new Run Properties to preserve bold, italic and underline style of characters in Word document.
This is what I want to store in a word document:
This is the example for applying bold, italic and underline style to characters in Word document.
Below are the codes generated by DocumentReflector (a tool shipped with SDK), you may pay attention to codes in red.
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
namespace GeneratedCode
{
public class GeneratedClass
{
public static Document GenerateDocument()
{
var element =
new Document(
new Body(
new Paragraph(
new Run(
new Text("This is the example for applying "){ Space = "preserve" }),
new Run(
new RunProperties(
new Bold()),
new Text("bold")
){ RsidRunProperties = "00FA7F5A" },
new Run(
new Text(", "){ Space = "preserve" }),
new Run(
new RunProperties(
new Italic()),
new Text("italic")
){ RsidRunProperties = "00FA7F5A" },
new Run(
new Text(" and "){ Space = "preserve" }),
new Run(
new RunProperties(
new Underline(){ Val = UnderlineValues.Single }),
new Text("underline")
){ RsidRunProperties = "00FA7F5A" },
new Run(
new Text(" style to characters in Word document."){ Space = "preserve" })
){ RsidParagraphAddition = "004E0028", RsidRunAdditionDefault = "00FA7F5A" },
new SectionProperties(
new PageSize(){ Width = (UInt64Value)12240UL, Height = (UInt64Value)15840UL },
new PageMargin(){ Top = 1440, Right = (UInt64Value)1800UL, Bottom = 1440, Left = (UInt64Value)1800UL, Header = (UInt64Value)720UL, Footer = (UInt64Value)720UL, Gutter = (UInt64Value)0UL },
new Columns(){ Space = (UInt64Value)720UL },
new DocGrid(){ LinePitch = 360 }
){ RsidR = "004E0028", RsidSect = "004E0028" }));
return element;
}
}
}
Is it helpful?