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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

insert element in bookmark and keep the same format of the current paragraph

Thread ID:

Created:

Updated:

Platform:

Replies:

143954 Apr 11,2019 01:14 PM UTC Apr 15,2019 10:09 AM UTC WinForms 3
loading
Tags: DocIO
AtliDev
Asked On April 11, 2019 01:14 PM UTC

hi
i want to add paragraph in the bookmark and keeep the same format and caractere style of the current paragraph
like
     this is a paragraph [other paragraph of element] suite of the paragraph
this is wrong what i want is:
     this is a paragraph [other paragraph of element] suite of the paragraph

my code :

        Dim a As WordDocument = New WordDocument(chemin + "\testword\mehdi.doc", FormatType.Doc)
        Dim bknav As BookmarksNavigator = New BookmarksNavigator(a)
        bknav.MoveToBookmark("casa")



        Dim d As WordDocument = New WordDocument
        Dim tbp As TextBodyPart = New TextBodyPart(d)
        Dim para As WParagraph = d.CreateParagraph

        para.Text = "paragraph of element"

        tbp.BodyItems.Add(para)
        bknav.ReplaceBookmarkContent(tbp)
        d.Close()
        tbp.Close()




thanks

Abirami Varadharajan [Syncfusion]
Replied On April 12, 2019 11:59 AM UTC

Hi AtliDev, 
 
To meet your requirement, we suggest you to set the formats and then replace the bookmark content in the Word document. Please refer the below highlighted code example to apply character and paragraph format at your end.
  
Dim a As WordDocument = New WordDocument("Sample.docx", FormatType.Doc)  
Dim bknav As BookmarksNavigator = New BookmarksNavigator(a)  
bknav.MoveToBookmark("casa")  
Dim d As WordDocument = New WordDocument  
Dim tbp As TextBodyPart = New TextBodyPart(d)  
Dim para As WParagraph = d.CreateParagraph  
  
'Append text into the paragraph.  
Dim textRange As IWTextRange = para.AppendText("paragraph of element")  
'Set character format for text.  
textRange.CharacterFormat.Bold = True  
'Apply paragraph format for the paragraph.  
para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center  
  
tbp.BodyItems.Add(para)  
  
bknav.ReplaceBookmarkContent(tbp)  
d.Close()  
tbp.Close()  
  
a.Save("Result.docx")  

Please refer the below UG documentation link to know more about applying paragraph and character format in the Word document:
https://help.syncfusion.com/file-formats/docio/working-with-paragraph
 
 
Regards, 
Abirami 


AtliDev
Replied On April 12, 2019 12:17 PM UTC

hi,
thanks for reply,
same time the bookmark have a specific charterformat different of the format of paragraph.
and when i want to insert element in bookmark , i want just to save the format of the bookmark

thanks


Abirami Varadharajan [Syncfusion]
Replied On April 15, 2019 10:09 AM UTC

Hi AtliDev, 

We suspect that your requirement is to preserve the character formats of bookmark contents to the replacement contents. In the Word document, bookmarks are references and doesn’t contain character formats. To meet your requirement, we suggest you to get the character format from bookmark content and set the same character format to replacement contents. Please refer the sample for the same from the below link:

 
Sample Link:http://www.syncfusion.com/downloads/support/forum/143954/ze/Sample_application-1965261608 

In this sample, we have done the following things:
 1. Loads an existing Word document.
 2. Get the character format from text of bookmark content.
 3. Create new contents and set formats.
 4. Replace the bookmark content in the Word document.
 5. Saves the Word document.

If the above sample doesn’t meet your end requirement means, kindly share us the input Word document and the expected output document. Thereby, we will check on your requirements and will update you the solution at the earliest. 

Regards, 
Abirami 


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

This page will automatically be redirected to the 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

Live Chat Icon For mobile
Live Chat Icon