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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Need help with pasting HTML to Document

Thread ID:

Created:

Updated:

Platform:

Replies:

120062 Aug 27,2015 08:57 AM UTC Aug 31,2015 07:22 AM UTC ASP.NET MVC 4
loading
Tags: DocIO
lc
Asked On August 27, 2015 08:57 AM UTC

HI,
i'm trying to put some HTML part from a rte editor to my generated word document.

Most of the document ist pasted using MailMerge. At one Point i want to add html data so i got a placeholder there: <<TempPlaceHolderForHTML>>

this is getting my placeholdertext:

Dim selection As TextSelection = doc.Find(New System.Text.RegularExpressions.Regex("<<TempPlaceHolderForHTML>>"))

with this im pasting my html to another document. i thought this would be the best to add the parts to the document:

Private Function HTMLtoRTF(htmltext As String) As EntityCollection
            Dim document As WordDocument = New WordDocument()
            Dim section As IWSection = document.AddSection()
            Dim para As IWParagraph = section.AddParagraph()

            document.XHTMLValidateOption = XHTMLValidationType.Transitional
            section.Body.InsertXHTML(htmltext)
            Return section.ChildEntities
End Function

unfortunately this is not working: 

Dim foo2 As New TextBodyPart(selection)
                Dim blubb = HTMLtoRTF(currentUser.ProfilInteressen.Text)

                For Each fob In blubb
                    foo2.PasteAtEnd(fob)
                Next

Does anyone know hot to continue at this point or is there maybe an easy way im overseeing?

Kind regards,
lc

lc
Replied On August 27, 2015 11:04 AM UTC

i found a solution, but there should be some easier approach to this problem:

Private Function FindCell(doc As WordDocument, searchString As String) As WTableCell
            For Each it As IWSection In doc.Sections
                For Each blu As WTable In it.Tables
                    For Each blu2 As WTableRow In blu.Rows
                        For Each cl As WTableCell In blu2.Cells
                            Dim temp = blu2.Cells.Count
                            For Each pg As WParagraph In cl.Paragraphs
                                If pg.Text.Contains(searchString) Then
                                    Return cl
                                End If
                            Next
                        Next
                    Next
                Next
            Next
            Return Nothing
        End Function


Dim cell = FindCell(doc, "<<TempPlaceHolderForHTML>>")
                If Not IsNothing(cell) Then
                    Dim pgCount = cell.Paragraphs.Count()
                    For i As Integer = pgCount - 1 To 0 Step -1
                        cell.Paragraphs.RemoveAt(i)
                    Next
                    Dim tempParagraph = cell.AddParagraph()
                    tempParagraph.AppendHTML(htmlString)
                End If

Divyalakshmi Vasudevan [Syncfusion]
Replied On August 28, 2015 07:34 AM UTC

Hi IC,

Thank you for your interest in Syncfusion products.


Kindly make use of below code snippet to meet your requirement by using Find and Replace functionality of DocIO .



Example:


'Loads the Word Document

            Dim document As New WordDocument(filename)


            'Find the <<TempPlaceHolderForHTML>> text

            Dim selections As TextSelection() = document.FindAll(New System.Text.RegularExpressions.Regex("<<TempPlaceHolderForHTML>>"))


            For selectionIndex As Integer = 0 To selections.Length - 1

                Dim selection As TextSelection = selections(selectionIndex)

                Dim OwnerParagraph As WParagraph = selection.GetAsOneRange().OwnerParagraph

                'Retrieve the Owner cell

                If TypeOf OwnerParagraph.OwnerTextBody Is WTableCell Then

                    Dim cell As WTableCell = TryCast(OwnerParagraph.OwnerTextBody, WTableCell)

                    'Clear the paragraphs inside the cell

                    cell.ChildEntities.Clear()

                    Dim paragraph As IWParagraph = cell.AddParagraph()

                    'Append the HTML string to the paragraph

                    paragraph.AppendHTML(htmlstring)

                End If

            Next

            'Saves the Word document to disk

            document.Save("Sample.docx")


Kindly refer the below UG documentation link to get more information about Find and Replace:


UGLink:


http://help.syncfusion.com/ug/aspnetmvc/Documents/findandreplace.htm



Please let us know if you have any other questions.


Regards,
Divyalakshmi V


lc
Replied On August 28, 2015 11:49 AM UTC

Hi Divyalakshmi,
thanks this looks much easier than my code. selection.GetAsOneRange().OwnerParagraph was the connection i could not find in the samples.

Regards,
LC

Sivasubramani V [Syncfusion]
Replied On August 31, 2015 07:22 AM UTC

Hi IC,

Thank you for your update.

We have prepared a sample to find and replace the particular content with html string using find and replace functionality of DocIO. Please find the sample from below link

Sample link:

http://www.syncfusion.com/downloads/support/forum/120062/ze/Sample-1088296552

Please let us know if you have any other questions.

Regards,
Siva.



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.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon 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.Close Icon

;