title: Bold a part of string/range in each line using Microsoft.Office.Interop.Word
body: <p>I have seen few codes to bold a part of range but those are specific to those examples. In my case I am writing datagridview values to word using Microsoft.Office.Interop.Word. I want to bold a specific value to be bold/italic. I am using following code.</p>
  
  <pre><code>        Microsoft.Office.Interop.Word.Application objword = new Microsoft.Office.Interop.Word.Application();
          objword.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateNormal;
          Microsoft.Office.Interop.Word.Document objDoc = objword.Documents.Add();
  
          Microsoft.Office.Interop.Word.Paragraph para1;
          para1 = objDoc.Paragraphs.Add();
          String text = "";
          for (int r = 0; r &lt; dgvlib.RowCount; r++)
          {
              text = text + dgvlib.Rows[r].Cells[1].Value.ToString();
              if (dgvlib.Rows[r].Cells[11].Value.ToString()!="")
                  text = text +  " Comments:" + dgvlib.Rows[r].Cells[11].Value.ToString() + " ";
              if (dgvlib.Rows[r].Cells[10].Value.ToString() != "")
                  text = text +  " ( Bold Text:" + dgvlib.Rows[r].Cells[10].Value.ToString() + ")";
              text = text + "\n";
          }
          para1.Range.Font.Size = 9;
          para1.Range.Font.Name = "Arial";
          para1.Range.Text = text;
          para1.Range.Paragraphs.Add();
          objDoc.SaveAs2(fNameExportWord);
          objword.Visible = true;
  </code></pre>
  
  <p>I want to bold only this text dgvlib.Rows[r].Cells[10].Value.ToString() (second if condition). If I use different ranges or para then it creates new paragraphs.</p>
  
  <p>In fact datagrid view dgblib rows are being written line by line so in each new line the value to be bold is dynamic. Sample to be written is below (if rows are 3).</p>
  
  <p>this is row to be written to the word. Comments: these are comments. (Bold Text: <strong>456</strong>)</p>
  
  <p>this is row2 to be written to the word. Comments: these are comments. (Bold Text: <strong>789</strong>)</p>
  
  <p>this is row3 to be written to the word. Comments: these are comments. (Bold Text: <strong>123</strong>)</p>