• word2007插件开发经验备忘3如何操作文本字体


    文本设置就是设置Font的属性,设置为Word.Font的类


    但是有个问题,如何把一列文本中的特定字设置字体呢?

    代码
    public void AddToTable(Word.Table table, int row, string docName)
    {
    table.Cell(row,
    2).Range.Text = this.TDICatelog1;
    table.Cell(row,
    3).Range.Text = this.TDISubCatelog1;

    #region Add description table.Cell(row, 4)
    Word.Font normalFont
    = table.Cell(row, 3).Range.Font;
    string description = "Title:\n" + docName + ":" + this.TDITitle1 + "\nSection:\n" + this.TDISection1 + "\nPage:\n" + this.TDIPage1 + "\nTechnical Document Content:\n"
    + this.TDIContent1 + "\nTechnical Document Issue:\n" + this.TDIIssue1 + "\nRecommended Change:\n" + this.TDICommendChange1 + "\nReproduction Steps:\n";
    table.Cell(row,
    4).Range.Text = description;
    table.Cell(row,
    4).Range.Select();
    Word.Selection seletionText
    = table.Application.Selection;
    Word.Find find
    = seletionText.Find;
    object FindText = docName;
    object MatchCase = false;
    object MatchWholeWord = true;
    object MatchWildcards = false;
    object MatchSoundsLike = false;
    object MatchAllWordForms = false;
    object Forward = true;
    object Wrap = Word.WdFindWrap.wdFindStop;
    object Find_Format = false;
    object ReplaceWith = docName;
    object Replace = Word.WdReplace.wdReplaceNone;
    object MatchKashida = false;
    object MatchDiacritics = false;
    object MatchAlefHamza = false;
    object MatchControl = false;
    if (find.Execute(ref FindText, ref MatchCase, ref MatchWholeWord, ref MatchWildcards, ref MatchSoundsLike, ref MatchAllWordForms, ref Forward, ref Wrap, ref Find_Format, ref ReplaceWith, ref Replace,
    ref MatchKashida, ref MatchDiacritics, ref MatchAlefHamza, ref MatchControl))
    {
    seletionText.Font
    = normalFont;
    }

    //Change teh TDITitile;
    table.Cell(row, 4).Range.Select();
    seletionText
    = table.Application.Selection;
    FindText
    = ":" + this.TDITitle1;
    if (find.Execute(ref FindText, ref MatchCase, ref MatchWholeWord, ref MatchWildcards, ref MatchSoundsLike, ref MatchAllWordForms, ref Forward, ref Wrap, ref Find_Format, ref ReplaceWith, ref Replace,
    ref MatchKashida, ref MatchDiacritics, ref MatchAlefHamza, ref MatchControl))
    {
    seletionText.Font
    = normalFont;
    }

    //Change teh TDISection;
    table.Cell(row, 4).Range.Select();
    seletionText
    = table.Application.Selection;
    FindText
    = TDISection1;
    if (find.Execute(ref FindText, ref MatchCase, ref MatchWholeWord, ref MatchWildcards, ref MatchSoundsLike, ref MatchAllWordForms, ref Forward, ref Wrap, ref Find_Format, ref ReplaceWith, ref Replace,
    ref MatchKashida, ref MatchDiacritics, ref MatchAlefHamza, ref MatchControl))
    {
    seletionText.Font
    = normalFont;
    }

    //Change teh TDIPage;
    table.Cell(row, 4).Range.Select();
    seletionText
    = table.Application.Selection;
    FindText
    = this.TDIPage1;
    if (find.Execute(ref FindText, ref MatchCase, ref MatchWholeWord, ref MatchWildcards, ref MatchSoundsLike, ref MatchAllWordForms, ref Forward, ref Wrap, ref Find_Format, ref ReplaceWith, ref Replace,
    ref MatchKashida, ref MatchDiacritics, ref MatchAlefHamza, ref MatchControl))
    {
    seletionText.Font
    = normalFont;
    }

    //Change teh TDIContent;
    table.Cell(row, 4).Range.Select();
    seletionText
    = table.Application.Selection;
    FindText
    = this.TDIContent1;
    if (find.Execute(ref FindText, ref MatchCase, ref MatchWholeWord, ref MatchWildcards, ref MatchSoundsLike, ref MatchAllWordForms, ref Forward, ref Wrap, ref Find_Format, ref ReplaceWith, ref Replace,
    ref MatchKashida, ref MatchDiacritics, ref MatchAlefHamza, ref MatchControl))
    {
    seletionText.Font
    = normalFont;
    }

    //Change teh TDIIssue;
    table.Cell(row, 4).Range.Select();
    seletionText
    = table.Application.Selection;
    FindText
    = this.TDIIssue1;
    if (find.Execute(ref FindText, ref MatchCase, ref MatchWholeWord, ref MatchWildcards, ref MatchSoundsLike, ref MatchAllWordForms, ref Forward, ref Wrap, ref Find_Format, ref ReplaceWith, ref Replace,
    ref MatchKashida, ref MatchDiacritics, ref MatchAlefHamza, ref MatchControl))
    {
    seletionText.Font
    = normalFont;
    }

    //Change teh TDICommentChange;
    table.Cell(row, 4).Range.Select();
    seletionText
    = table.Application.Selection;
    FindText
    = this.TDICommendChange;
    if (find.Execute(ref FindText, ref MatchCase, ref MatchWholeWord, ref MatchWildcards, ref MatchSoundsLike, ref MatchAllWordForms, ref Forward, ref Wrap, ref Find_Format, ref ReplaceWith, ref Replace,
    ref MatchKashida, ref MatchDiacritics, ref MatchAlefHamza, ref MatchControl))
    {
    seletionText.Font
    = normalFont;
    }
    #endregion

    table.Cell(row,
    5).Range.Text = "Spec Review";
    table.Cell(row,
    6).Range.Text = "Bug ID \nto be reivewed\n";
    table.Cell(row,
    7).Range.Text = "3";
    table.Cell(row,
    8).Range.Text = "3";
    }

    就是使用find.execute()这个函数,相当于查找+选中,于是问题就解决了.....

    实时了解作者更多技术文章,技术心得,请关注微信公众号“轩脉刃的刀光剑影”

    本文基于署名-非商业性使用 3.0许可协议发布,欢迎转载,演绎,但是必须保留本文的署名叶剑峰(包含链接http://www.cnblogs.com/yjf512/),且不得用于商业目的。如您有任何疑问或者授权方面的协商,请与我联系

  • 相关阅读:
    黑马程序员JAVA高级视频_IO输入与输出18天2(FileWriter)
    黑马程序员JavaAPI17天5(集合转成数组)
    黑马程序员JAVA高级视频_IO输入与输出19天4(MyBufferedReader)
    android 取消webview的背景色
    DLNA
    Android JNI的若干问题总结
    gcc 一些应用
    如何基于nand flash启动Linux内核(分享一段实用、简单、类似bootloader功能的代码)
    Android JNI开发高级篇有关Android JNI开发中比较强大和有用的功能就是从JNI层创建、构造Java的类或执行Java层的方法获取属性等操作。 一、类的相关操作 1. jclass FindClass(JNIEnv *env, const char *name);
    ubuntu 配置ndk
  • 原文地址:https://www.cnblogs.com/yjf512/p/1864409.html
Copyright © 2020-2023  润新知