0

我正在用 c# 编写一段代码以在 microsft word 文档中生成报告。

  • 我有一个 2 列的表格。
  • 我选择第二列

    oMainTable.Cell(currentRowNumber, 2).Range

  • 每次我必须在该单元格中写一些东西时,我都会使用上面的代码与 Text 属性、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 应用下划线和粗斜体,这样它们就不适用​​于整个范围;并且仅限于这两个文本行。

有什么帮助吗?

谢谢

4

1 回答 1

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,否则我不会得到正确的选择。

请提出更好的方法..

于 2009-06-17T16:14:08.550 回答