2009-06-16 39 views
0

我在c#中编写了一段代码以在microsft word文档中生成报告。范围:将格式应用于范围中的子部分

  • 我有一个wid 2列的表。
  • 我通过

    oMainTable.Cell选择第2列(currentRowNumber,2).Range

  • 每次我必须写在该细胞我使用上面的代码与文字的组合的东西财产,InsertParagraph(),InsertAfter()等等等等

现在让我们说我有这样的内容:

部分样本内容部分样本 内容部分样本内容部分样本内容 部分样本内容 部分样本内容部分样本 内容。

New Paragraph Some sample content Some sample content Some sample 

内容的一些样本内容的一些 样本内容的一些样本内容 一些样本内容

Some Title1 

New Paragraph Some sample content Some sample content Some sample 

内容的一些样本内容的一些 样本内容的一些样本内容 一些样本内容

New Paragraph Some sample content Some sample content Some sample 

内容部分样本内容部分 样品内容有些样品含量 一些样本内容

Some Title1 

我想强调和粗斜体适用于someTitle1和someTitle2使得它们并不适用于整个范围内;并仅限于这两条文本。

任何帮助?

感谢

+0

我忙着它..请参阅下面的答案。 – 2009-06-18 15:02:23

回答

0

让我先发一个声明;-)“**这里提出的解决方案是我的命中和试验方法的结果,并撞头**”

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; 
    } 

我在做这个一个循环,所以每次我必须做Range.Select,否则我wouldnt得到正确的选择。

请建议更好的方法..