当我尝试设置选择代码风格与样式:
Microsoft.Office.Interop.Word.Application oWordApp = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
Microsoft.Office.Interop.Word.Selection currentSelection = oWordApp.Selection;
object codeStyle = "Code";
// this disrespects the background
currentSelection.set_Style(ref codeStyle);
它忽略了背景色(lightblue):
当我把它应用到的范围内,它会为整款:
Microsoft.Office.Interop.Word.Application oWordApp = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
Microsoft.Office.Interop.Word.Selection currentSelection = oWordApp.Selection;
// this sets the style to the whole paragraph, but i want the range only
currentSelection.Range.set_Style(ref codeStyle);
定义的“代码”是:
我只希望在代码风格字/选择“攻击”。我究竟做错了什么?当我录制一个宏它给了我这样的:
Selection.Style = ActiveDocument.Styles("Code")
但是这并不能帮助我太多...
我发现这个问题。您可以附加一个样式后的风格基础:
Microsoft.Office.Interop.Word.Application oWordApp = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
Microsoft.Office.Interop.Word.Selection currentSelection = oWordApp.Selection;
object codeStyle = "Code Char"; //appending Char made its job!
currentSelection.Range.set_Style(ref codeStyle);