title: OpenXML C#: Change color of a word in wordprocessing
body: <p>I want to change the color of a word. I am adding color in runproperties but instead of changing color of single word it change the color of whole line. see the code.</p>
  
  <pre><code>void AppendStyle(string document, string word, string col)
      {
          try
          {
              using (WordprocessingDocument wordDoc =
                      WordprocessingDocument.Open(document, true)) //Open file from path
              {
                  var body = wordDoc.MainDocumentPart.Document.Body;
                  var paras = body.Elements&lt;Paragraph&gt;();
                  DocumentFormat.OpenXml.Wordprocessing.Color color = new DocumentFormat.OpenXml.Wordprocessing.Color();
  
                  foreach (var para in paras)
                  {
                      foreach (var run in para.Elements&lt;Run&gt;())
                      {
                          foreach (var text in run.Elements&lt;Text&gt;())
                          {
                              if (text.Text.Contains(word))
                              {
  
                                  color.Val = col;
                                  run.AppendChild(color);
                                  return;
                              }
  
                          }
                      }
                  }
  
                  wordDoc.Close(); // close the template file
  
              }
  </code></pre>