【问题标题】:range : apply formatting to a sub section in the rangerange : 将格式应用于范围内的子部分
【发布时间】:2009-08-07 20:55:34
【问题描述】:

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

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

    oMainTable.Cell(currentRowNumber, 2).Range

  • 每次我必须在该单元格中写一些东西时,我都会使用上面的代码以及 Text 属性、InsertParagraph()、InsertAfter() 等的组合

现在假设我有这个内容:

一些示例内容一些示例 内容 一些示例内容 一些 示例内容 一些示例内容 部分示例内容 部分示例 内容。

New Paragraph Some sample content Some sample content Some sample

content 一些示例内容 Some 示例内容 一些示例内容 部分示例内容

Some Title1

New Paragraph Some sample content Some sample content Some sample

content 一些示例内容 Some 示例内容 一些示例内容 部分示例内容

New Paragraph Some sample content Some sample content Some sample

content 一些示例内容 Some 示例内容 一些示例内容 部分示例内容

Some Title1

我想对 someTitle1 和 someTitle2 应用下划线和粗斜体,这样它们就不会应用到整个范围;并且仅限于这两个文本行。

有什么帮助吗?

谢谢

【问题讨论】:

  • 我把它弄出来了..请看下面的答案。

标签: c# interop ms-office office-automation word-automation


【解决方案1】:

让我先做一个免责声明 ;-)“**这里提出的解决方案是我的打击和试验方法以及头部撞击的结果**”

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

请提出更好的方法..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    相关资源
    最近更新 更多