We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Replacing a string with a paragraph

Thread ID:

Created:

Updated:

Platform:

Replies:

105221 Sep 19,2012 04:00 PM Oct 19,2012 07:58 AM ASP.NET Web Forms (Classic) 5
loading
Tags: DocIO
Todd J
Asked On September 19, 2012 04:00 PM

I need to find a string in my document and replace that string with a paragraph.  The paragraph also contains html.

here is the code I am using,  the replaced item in the document only includes the first line from the paragraph.

--start of code (vb.net)---------------------------------------------------
 Dim s As New WSection(document)
 Dim p As WParagraph = s.AddParagraph
 document.XHTMLValidateOption = XHTMLValidationType.Transitional
 p.AppendHTML(myHTMLstring)
 Dim tbpHTML As TextBodyPart
 tbpHTML = New TextBodyPart(document)
 tbpHTML.BodyItems.Add(p)
document.Replace("~html~", tbpHTML, True, True)
--end of code-------------------------------------------------------------

the field myHTMLstring contains this html string....

<b>Some line as a heading</b><br />
<ul>
 <li>the first bulleted item</li>
 <li>the second bulleted item</li>
 <li>the last bulleted item</li>
</ul>
-----------------------------------------------------------------
The replaced string in the document only contains:  
Some line as a heading

the rest of the html string is missing....how can I achieve this?

Thank you

Ramkumar M [Syncfusion]
Replied On September 20, 2012 04:39 AM

Hi Todd,

Thank you for your interest in Syncfusion products.

Appending html with list tag to a paragraph will create new paragraphs for those lists. So that we have to replace string by all those paragraphs. For your reference we have modified your code snippets. Please try this code and let us if this helps you.

  Dim s As New WSection(document)

  Dim p As WParagraph = s.AddParagraph

  document.XHTMLValidateOption = XHTMLValidationType.Transitional

  p.AppendHTML(myHTMLstring)

  Dim tbpHTML As TextBodyPart

  tbpHTML = New TextBodyPart(document)

  For index As Integer = 0 To s.Body.ChildEntities.Count - 1

      tbpHTML.BodyItems.Add(s.Body.ChildEntities(0))

  Next

  document.Replace("~html~", tbpHTML, True, True)

 

Please let us know if you have any questions.

Regards

Ramkumar


Todd J
Replied On September 20, 2012 10:32 AM

that works great...thank you very much!

Are they other tags besides the list tag that I will have to perform special processing for?

Ramkumar M [Syncfusion]
Replied On September 26, 2012 06:18 AM

Hi Todd,

Thank you for your updated.

Regarding your question about processing other tags:

No need to process each tag individually, the code snippets that I have provided in my last update will process all kinds of tags. For your reference, please find the code snippets below.

Code snippets:

  Dim s As New WSection(document)

  Dim p As WParagraph = s.AddParagraph

  document.XHTMLValidateOption = XHTMLValidationType.Transitional

  p.AppendHTML(myHTMLstring)

  Dim tbpHTML As TextBodyPart

  tbpHTML = New TextBodyPart(document)

  For index As Integer = 0 To s.Body.ChildEntities.Count - 1

      tbpHTML.BodyItems.Add(s.Body.ChildEntities(0))

  Next

  document.Replace("~html~", tbpHTML, True, True)

 

Please let us know if you have any questions.

 

Regards

Ramkumar


Todd J
Replied On October 16, 2012 05:36 PM

OK, now I have another challenge with this...It does work for me based on your code change.
But I am now trying to appendhtml into a table cell.  
Here is my code snippet: 

myHtmlString looks like this
<b>Item Highlights</b>
<ul>
<li>Clear Case</li>
<li>Blank Sheet</li>
<li>Heavy Duty</li>
</ul>

here is a scaled down version of the sub routine that I call to append the html.

private sub FormatHtml(byval myHtmlString as string, byRef cell As WTableCell)
    cell.Document.XHTMLValidateOption = XHTMLValidationType.Transitional
    cell.AddParagraph.AppendHTML(myHtmlString)
end sub

this does work but the spacing is too big, see attached example output file.

The spacing before and after the bullets is too big.  any way to reduce this?



append html in subtable_d0e4891f.zip

Ramkumar M [Syncfusion]
Replied On October 19, 2012 07:58 AM

Hi Todd,
Thank you for your update.
Please use the below code snippets to remove the before and after spacing of paragraphs present in the cell and let us know if this helps you.
Code snippets:
        Private Sub FormatHtml(ByVal myHtmlString As String, ByRef cell As WTableCell)
            cell.Document.XHTMLValidateOption = XHTMLValidationType.Transitional
            cell.AddParagraph.AppendHTML(myHtmlString)
            RemoveParagraphSpacing(cell)
        End Sub
 
        Private Sub RemoveParagraphSpacing(cell As WTableCell)
            For Each item As Entity In cell.ChildEntities
                Dim para As WParagraph = DirectCast(item, WParagraph)
                para.ParagraphFormat.SpaceAfterAuto = False
                para.ParagraphFormat.SpaceBeforeAuto = False
                para.ParagraphFormat.BeforeSpacing = 0
                para.ParagraphFormat.AfterSpacing = 0
            Next
        End Sub
 
Please let us know if you have any questions
Regards
Ramkumar

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;