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

Create a merge field

Thread ID:

Created:

Updated:

Platform:

Replies:

62976 Jun 26,2007 03:34 PM UTC Jun 29,2007 07:31 AM UTC WinForms 6
loading
Tags: DocIO
BONIFACIO
Asked On June 26, 2007 03:34 PM UTC

Hello,

I would like to know if we can create a new merge field using Essential DocIO.

I need this information in order to create a sort of "assistant" for word.

kind regards,

L. BONIFACIO

Melba Winshia [Syncfusion]
Replied On June 27, 2007 12:14 PM UTC

Hi Lionel,

Thank you for your interest in Essential DocIO.

Yes, you can create a new merge field using Essential DocIO. Please refer the following code snippet to achieve this:

[C#]

// Inserting MergeFields.
paragraph.AppendField( "Name" , Syncfusion.DocIO.FieldType.FieldMergeField );

paragraph = section.AddParagraph();
paragraph.AppendField ( "Age" , Syncfusion.DocIO.FieldType.FieldMergeField );

paragraph = section.AddParagraph();
paragraph.AppendField ( "Dept" , Syncfusion.DocIO.FieldType.FieldMergeField );

Here is the sample for your reference:

http://websamples.syncfusion.com/samples/DocIO.Windows/62976/main.htm

Kindly let me know if you have any other questions.

Thanks,
Melba

BONIFACIO
Replied On June 27, 2007 02:44 PM UTC

Thanks Melba for your help.

As I'm working in VB.NET, I translated your code :

**************

Dim doc as WordDocument
Dim paragraph As WParagraph
dim file as String = "C:\DocIO\test.doc

doc = New WordDocument
doc.Open(file)
paragraph = doc.LastParagraph

paragraph.AppendField("Name", Syncfusion.DocIO.FieldType.FieldMergeField)

paragraph.AppendField("Age", Syncfusion.DocIO.FieldType.FieldMergeField)

paragraph.AppendField("Dept", Syncfusion.DocIO.FieldType.FieldMergeField)

doc.Save(file)

*****************

The three mergefields are created. The problem is their name. Indeed, the name is not (for exemple) "Name", but "Name Name".

Do you know how I could change the name ? I'll try to resolve the problem, but some help is welcome.

Kinds regards,

L. BONIFACIO

Melba Winshia [Syncfusion]
Replied On June 28, 2007 12:55 PM UTC

Hi Lionel,

Thank you for the update.

I am not sure if I understand your requirements. Could you please let me know if you want to change the field name "Name" as "Name Name"? If this is the case you can use the following code snippet to achieve this:

[C#]

// Inserting MergeFields.
paragraph.AppendField( "Name Name" , Syncfusion.DocIO.FieldType.FieldMergeField );

If this is not the case could you please provide more details regarding "The problem is their name"? This would help me in investigating this issue further.

Thanks,
Melba

BONIFACIO
Replied On June 28, 2007 01:17 PM UTC

Hello Melba,

This line is correct :
paragraph.AppendField("Age", Syncfusion.DocIO.FieldType.FieldMergeField)

The problem appears when I want to see the name of the MergeField in my document.
I have this : {MERGEFIELD Age Age}
The name is dubbled.

I see I can create a new interface of IWMergeField, but I don't know where I can insert it in my document (or in a paragraph).

Kind regards,
L.BONIFACIO

BONIFACIO
Replied On June 28, 2007 02:08 PM UTC

Hello,

it's just to say that my problem is solved.
I succeeded in create a merge field with a good name (for me).

This is the code I made in VB.NET :

Dim document As WordDocument = New WordDocument()

'Opening DOC
document.Open("C:\DocIO\test.doc")

'Add a new section to the document
Dim section As IWSection = document.AddSection()

'Add a new paragraph to the section.
Dim paragraph As IWParagraph = ection.AddParagraph()

'Insert Text into the paragraph
paragraph.AppendText("Hello World!" & Chr(13))

'Insert MergeField in the paragraph
Dim mergeField As IWMergeField

mergeField = paragraph.AppendField("", FieldType.FieldMergeField)
mergeField.FieldName = "Name"

mergeField = paragraph.AppendField("", FieldType.FieldMergeField)
mergeField.FieldName = "Age"

mergeField = paragraph.AppendField("", FieldType.FieldMergeField)
mergeField.FieldName = "Dept"

'Saving the document to disk.
document.Save("C:\DocIO\result.doc")


L. BONIFACIO

Melba Winshia [Syncfusion]
Replied On June 29, 2007 07:31 AM UTC

Hi Lionel,

Glad to hear that problem is resolved.

Kindly let me know if you have any other questions.

Thanks,
Melba

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.

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

;