Version

ApplyCharacterStyle Method

Applies specified character style to runs in the specified span.
Syntax
'Declaration
 
Public Sub ApplyCharacterStyle( _
   ByVal span As DocumentSpan, _
   ByVal styleId As String, _
   ByRef error As String, _
   Optional ByVal clearExistingCharacterSettings As Boolean _
) 
public void ApplyCharacterStyle( 
   DocumentSpan span,
   string styleId,
   out string error,
   bool clearExistingCharacterSettings
)

Parameters

span
Document span to apply the changes to.
styleId
Id of a character style in the root node's DocumentRootNode.Styles collection or AvailableStyles collection of the document. In the latter case the style will be copied from the available styles into the root node's styles collection.
error
If a character style with the specified id doesn't exist or if any other error occurs, this will be set to the error message.
clearExistingCharacterSettings
Specifies whether to clear runs' explicit RunNode.Settings. If a run has had some formatting applied to it previously then its Settings would have been set accordingly. A run's Settings property takes precedence over the RunNode.StyleId style settings. Therefore passing in True for this parameter will ensure the settings from the specified style don't get overridden by RunNode's Settings.
Remarks

ApplyCharacterStyle method sets the RunNode.StyleId property of runs that are contained by the specified span. If a run partially spans the specified document span then the run will be broken up as necessary so that only the content that's contained by the span is applied the specified character style.

Note that if any run in the span has a style id previously set, that will be reset to the specified styleId.

Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also