Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Description

Excerpt

User-assigned delegate method that is called after HTMLToWord inserts an Element into the Word document. The user may implement code to perform additional formatting or post-processing on the Element inserted into the document. If this delegate is not set, HTMLToWord simply continues processing.

Signature
C#
C#
<table class="diff-macro"><thead><tr><th class="diff-macro-title">unmigrated-wiki-markup</th></tr></thead><tbody><tr><td class="diff-macro-body"><pre>
 public FormatElementDelegate FormatDelegate{ get; set; }
</pre></td></tr></tbody></table>
Signature
vb.net
vb.net
Public <p>Public Property FormatDelegate() As FormatElementDelegate</p>FormatElementDelegate
Example
Code Block
csharp
csharp
titleC#
 
 void MyFormatter(Element insertedElement, XmlNode node)
 {
      string nodeName = node.Name.ToLower();
 
      if (nodeName.Equals("ul"))
      {
           //--- First, cast the WordWriter Element object (passed in as a parameter to this method)
           //--- to a WordWriter List object.
           List theList = (List)insertedElement;

           //--- We want bulleted lists to have 1 line of spacing above and below to offset them
           //--- from the text.  This mimics the behavior of most HTML renderers.
 
           //--- Get the font size used in the list.  We'll use that value to determine
           //--- the appropriate line spacing gap.
           double fontSize = theList.GetEntry(0).Style.Font.FontSize;
           theList.GetEntry(0).Formatting.SpaceBefore = TwipsConverter.FromPoints(fontSize);
           theList.GetEntry(theList.NumEntries - 1).Formatting.SpaceAfter =
                TwipsConverter.FromPoints(fontSize);
      }   
 }


 //--- Create an HTMLToWord instance.
 HTMLToWord h2w = new HTMLToWord();
  
 //--- Tell HTMLToWord that it should call our "MyFormatter" delegate method 
 //--- whenever an Element is inserted into the Word document.
 h2w.FormatDelegate = new HTMLToWord.FormatElementDelegate(MyFormatter);
Code Block
vb.net
vb.net
titlevb.net
 
 Sub MyFormatter(Element insertedElement, XmlNode node)
      Dim nodeName As String = node.Name.ToLower()

      If nodeName.Equals("ul") Then
           '--- First, cast the WordWriter Element object (passed in as a parameter to this method)
           '--- to a WordWriter List object.
           Dim theList As List = insertedElement

           '--- We want bulleted lists to have 1 line of spacing above and below to offset them
           '--- from the text.  This mimics the behavior of most HTML renderers.
 
           '--- Get the font size used in the list.  We'll use that value to determine
           '--- the appropriate line spacing gap.
           Dim fontSize As Double = theList.GetEntry(0).Style.Font.FontSize
           theList.GetEntry(0).Formatting.SpaceBefore = TwipsConverter.FromPoints(fontSize)
           theList.GetEntry(theList.NumEntries - 1).Formatting.SpaceAfter = _
                TwipsConverter.FromPoints(fontSize)
      End If   
 End Sub



 '--- Create an HTMLToWord instance.
 Dim h2w As New HTMLToWord()
  
 '--- Tell HTMLToWord that it should call our "MyFormatter" delegate method 
 '--- whenever an Element is inserted into the Word document.
 h2w.FormatDelegate = New HTMLToWord.FormatElementDelegate(AddressOf MyFormatter)