设置标题级别

object st = wordApp.Selection.End;
wordDoc.Range(ref st, ref st).set_Style(Word.WdBuiltinStyle.wdStyleHeading1); //设置标题属性只能设置整段,无法在某行局部设置标题属性,在某点设置标题,就是设置整段。

//前面的标题行输入回车后,设置后续内容为正文属性

ed = wordApp.Selection.End;
wordDoc.Range(ref ed, ref ed).set_Style(Word.WdBuiltinStyle.wdStyleBodyText); //表名作为标题后,换行后必须将标题属性改为正文属性      

 

设置标题或正文后,字体将被设为默认值,所以还需重新设置字体。

例如:

object st = wordApp.Selection.End;                

wordDoc.Range(ref st, ref st).set_Style(Word.WdBuiltinStyle.wdStyleHeading1); //设置标题属性只能设置整段,无法在某行局部设置标题属性                                                wordApp.Selection.TypeText(dbTable.TableName+"\r\n"); //表名                

object ed = wordApp.Selection.End;                

Word.Range range = wordDoc.Range(ref st, ref ed);                               

range.Font.Bold = 1;                

range.Font.Size = 12;                

range.Font.Name = "TimesNewRoma";

ed = wordApp.Selection.End;                

wordDoc.Range(ref ed, ref ed).set_Style(Word.WdBuiltinStyle.wdStyleBodyText); //表名作为标题后,换行后必须将标题属性改为正文属性

wordApp.Selection.Font.Name = "TimesNewRoma";                

wordApp.Selection.Font.Bold = 0;                

wordApp.Selection.TypeText($"({dbTable.Package})   <<{dbTable.Type}>>\r\n");

                  

posted on 2019-06-05 18:12  mol1995  阅读(411)  评论(0编辑  收藏  举报

导航