{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.{excerpt} {signature:C#} public FormatElementDelegate FormatDelegate{ get; set; } {signature}{signature:vb.net} Public Property FormatDelegate() As FormatElementDelegate {signature} {example}{code:csharp|title=C#} 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} {code:vb.net|title=vb.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) {code} {example} |