range :将格式应用于范围内的子部分

发布于 2024-07-24 07:26:20 字数 881 浏览 3 评论 0原文

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

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

    oMainTable.Cell(currentRowNumber, 2).Range

  • 每次我必须在该单元格中写入内容时,我都会使用上面的内容与 Text 属性、InsertParagraph()、InsertAfter() 等组合的代码

现在假设我有这个内容:

一些示例内容一些示例 内容 一些 示例内容 一些 示例内容 一些示例内容 一些示例内容 一些示例 内容。

新段落 一些示例内容 一些示例内容 一些示例 
  

内容 一些示例内容 一些 示例内容 一些示例内容 一些示例内容

一些标题1 

  新段落 一些示例内容 一些示例内容 一些示例 
  

内容 一些示例内容 一些 示例内容 一些示例内容 一些示例内容

新段落 一些示例内容 一些示例内容 一些示例 
  

内容 一些示例内容 一些 示例内容 一些示例内容 一些示例内容

一些标题1 
  

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

有帮助吗?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忱杏 2024-07-31 07:26:20

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

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

请建议更好的方法..

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..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文