views:

108

answers:

1

I'm writing a piece of code in c# to generate a report in microsft word document.

  • I have a table of wid 2 columns.
  • I select the 2nd column by

    oMainTable.Cell(currentRowNumber, 2).Range

  • Every time I have to write something in that cell I use the above code with the combination of the Text property ,InsertParagraph(),InsertAfter() etc etc

Now lets say I have this content:

Some sample content Some sample content Some sample content Some sample content Some sample content Some sample content Some sample content.

New Paragraph Some sample content Some sample content Some sample

content Some sample content Some sample content Some sample content Some sample content

Some Title1

New Paragraph Some sample content Some sample content Some sample

content Some sample content Some sample content Some sample content Some sample content

New Paragraph Some sample content Some sample content Some sample

content Some sample content Some sample content Some sample content Some sample content

Some Title1

I want to apply underline and bold italics to someTitle1 and someTitle2 such that they don't apply to whole range; and remain limited to these two text lines only.

Any Help?

Thanks

A: 

Let me made a disclaimer first ;-) "**Solution presented here is outcome of my hit and trial approach and head banging **"

    object srchText="Text to be searched and formatted differently from the rest of the range";
    oTable.Cell(countRow, 2).Range.Select();
    var selectUpdateComment=oTable.Cell(countRow, 2).Range.Application.Selection;
    selectUpdateComment.Find.Execute2007(ref srchText, ref missing, ref missing,
 ref missing, ref missing, ref missing, ref missing, ref missing,
 ref missing, ref missing, ref missing, ref missing, ref missing,
 ref missing, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing);

    if(selectUpdateComment.Find.Found) {
        selectUpdateComment.Font.Bold=1;
        selectUpdateComment.Font.Underline=WdUnderline.wdUnderlineSingle;
    }

I WAS doing this in a loop so everytime i had to do Range.Select, otherwise i wouldnt get the right selection.

please suggest better approaches..

SilverHorse