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()这个函数,相当于查找+选中,于是问题就解决了.....

目录
相关文章
|
5月前
|
自然语言处理 程序员 编译器
`pylatex`是一个Python库,用于生成LaTeX文档。LaTeX是一种用于高质量排版和打印的文档准备系统,特别适用于科学、技术和数学文档。
`pylatex`是一个Python库,用于生成LaTeX文档。LaTeX是一种用于高质量排版和打印的文档准备系统,特别适用于科学、技术和数学文档。
|
5月前
实战范例——中文文章排版
实战范例——中文文章排版
26 0
搜索和替换PPT里面指定字体文字的(某些字体无法随演示文稿一起保存)解决方案
搜索和替换PPT里面指定字体文字的(某些字体无法随演示文稿一起保存)解决方案
190 0
|
7月前
|
Python
Python办公自动化【Word设置文字样式、Word设置段落样式、Word生成通知书、Word读取内容】(五)-全面详解(学习总结---从入门到深化)
Python办公自动化【Word设置文字样式、Word设置段落样式、Word生成通知书、Word读取内容】(五)-全面详解(学习总结---从入门到深化)
93 0
谈一谈|Markdown转为word文档
谈一谈|Markdown转为word文档
273 0
WORD必学技巧:标题和目录
WORD必学技巧:标题和目录
90 0
WORD必学技巧:标题和目录
WORD必学技巧:标尺与编辑标记
WORD必学技巧:标尺与编辑标记
108 0
WORD必学技巧:标尺与编辑标记
六石风格文档范例:做测试结果表格
六石风格文档范例:做测试结果表格
87 0
六石风格文档范例:做测试结果表格
Revit二次开发—创建文字注释(TextNote)
Revit二次开发—创建文字注释(TextNote)