开发者

How to use Heading Style while automating word in C#?

开发者 https://www.devze.com 2023-03-03 18:25 出处:网络
My program is copying string from other file and it should convert as heading while pasting in word. (MS 2007). I tried recording macro:

My program is copying string from other file and it should convert as heading while pasting in word. (MS 2007). I tried recording macro:

Selection.PasteAndFormat (wdPasteDefault)
Selec开发者_开发百科tion.Style = ActiveDocument.Styles("Heading 2").

But how to do it in C#?


Ok this is what I did:

object headingType = Word.WdBuiltinStyle.wdStyleHeading2;
wordApp.ActiveWindow.Selection.Range.PasteAndFormat(WdRecoveryType.wdPasteDefault);
wordApp.ActiveWindow.Selection.Range.set_Style(ref headingType);
0

精彩评论

暂无评论...
验证码 换一张
取 消