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. Image for the cookie policy date

change content of wtextbox

GoodMorning,
i have a wtextbox in my footer and i want to add text in ,

For Each sec As WSection In a.Sections
            For Each elem As Entity In sec.HeadersFooters.Footer.ChildEntities
                If TypeOf elem Is WParagraph Then
                    Dim para As WParagraph = elem
                    For Each ele As Entity In para.ChildEntities
                        If TypeOf ele Is WTextBox Then
                            Dim txt As WTextBox = ele
                            txt.TextBoxBody.LastParagraph.AppendText("Message")
                            txt.TextBoxFormat.FillColor = Color.Red
                        End If
                    Next
                End If
            Next
        Next


the color change in the second page and not in the first, but there is no text in the shape.



5 Replies

DB Dilli Babu Nandha Gopal Syncfusion Team December 26, 2018 04:49 PM UTC

Hi Aayadi, 
 
We suspect that the reported problem might be due to the formats used in the input Word document. So, could you please provide us the input Word document used to reproduce the exact problem at our side. This will be more helpful to analyze further and provide you the appropriate solution at the earliest.

Note: If you have any confidential data in your Word document, please replace with some dummy data and provide us the same. We just need your document to recreate the problem you face. 
 
Regards, 
Dilli babu 



AA AAYADI December 27, 2018 08:32 AM UTC

Hello,
here is the attached document,
the document contains two footers, and I can not write in the textbox of both footer.
the second thing is that I have a bookmark and in this bookmark i would just change the word between <*>
thanks a lot for your help.

Attachment: Files_ea205a28.zip


DB Dilli Babu Nandha Gopal Syncfusion Team January 3, 2019 07:33 AM UTC

Hi Aayadi, 
 
Regarding I cannot write in the textbox of both footer:
On further checking in the input Word document, the textbox in first page is in the first page header and the textbox in second page is in the odd footer. So, the reported problem occurs at your end, when add text in odd footer.

In the Word document, there are multiple Headers and Footers. To achieve your requirement, we suggest you to iterate into all headers and footers of each sections and then add the text in textbox. 
 
 
To know more about working with headers and footers, kindly refer the following link.
https://help.syncfusion.com/file-formats/docio/working-with-sections#working-with-headers-and-footers
 

Regarding i would just change the word between <*>:
     1. If your requirement is to replace the text with some other text means, we suggest you to use find and replace functionality of DocIO.
    2. If your requirement is to replace the text with some dynamic values (values obtained in run time or from database), we suggest you to use mail merge functionality of DocIO. To execute mail merge in the Word document, it is need to change the place holder text as merge field and then execute mail merge using DocIO.

Please refer the below links to know more about working with Word document using DocIO:
Find and replace functionality in DocIO
Working with mail merge
Online sample for mail merge functionality 
 

Also, we have prepared a sample application to achieve your requirement using the given Word document. Please find the sample from the below link:
Sample link:
http://www.syncfusion.com/downloads/support/forum/141663/ze/Sample-879647397 

In this sample, we have done the following things:
1. Loads an existing Word document.
2. Iterates into headers and footers and get the textbox.
3. Add text and fill color in textbox.
4. Replace the text using Replace API of DocIO.
5. Saves the Word document.
 
 
Regards, 
Dilli babu. 



AA AAYADI January 3, 2019 12:39 PM UTC

Hi Dilli,
thanks for the answers
for the textbox, i use your code but there is not box at the first page,
and to change the content between < > in a bookmark i use this code but it's not working.
then bookmark is like this
[hello mr <name>]



        Dim a As New WordDocument(chemin + "\testword\etpdp.doc")
        Dim bknav As BookmarksNavigator = New BookmarksNavigator(a)
        bknav.MoveToBookmark("hello")
        Dim tbp As TextBodyPart = bknav.GetBookmarkContent
        'Dim table As WTable = tbp.BodyItems(0)
        For Each item As Entity In tbp.BodyItems
            If TypeOf (item) Is WParagraph Then
                Dim existe As TextSelection = CType(item, WParagraph).Find(New System.Text.RegularExpressions.Regex("<name>"))   
                If Not existe Is Nothing Then
                    CType(item, WParagraph).Replace(existe.SelectedText, "AAYADI", True, False)
                End If
            End If
        Next



DB Dilli Babu Nandha Gopal Syncfusion Team January 7, 2019 12:23 PM UTC

Hi Aayadi,

Thank you for your patience.

Regarding Text box is not found in the first page:

Since the text box is floating, text box is preserved at right side corner of the output Word document at our end. 
Please find the output screen shot:
 
Regarding Bookmark content is not replaced:

We have modified the code example and input Word document (included name bookmark) in the sample. Please find the modified sample in below link:
http://www.syncfusion.com/downloads/support/forum/141663/ze/MODIFI~11114279238  
 
 
The content is replaced with an angular bracket in above sample, if you require angular brackets kindly append the brackets as a string in Replace code snippet.

Please refer the code snippet with angular brackets 
 
CType(item, WParagraph).Replace(existe.SelectedText, "<" + "AAYADI" + ">", True, False)  
 
Please let us know if you have any questions.  

Regards, 
 
Dilli babu. 


Loader.
Up arrow icon