Validity of DocVariables for Word template?

Hello,I have searching the site for info on using DocVariables instead of MailMerge Fields.Is it possible? Similar in application? Recommended at all?

I have quite a large bunch of documents with many DocVariables in use by each.

Some talk is to that fact that the Variable collection is not supported.How much has changed since then? Plus is it easier to work with DOCVariables now than before?

Please help me understand your approach with DocVariables in template word documents.

I don’t see how merge fields and document variables can be related or used one instead of another.

Merge fields are just Word fields. A merge field has a name. During mail merge the whole field can be replaced with data from your datasource. That’s the basics.

Document variables are just that. They are just variables. Each has a name and value. they are stored in the Document.Variables collection. You can add and remove them. User does not see them anywhere in the document. Document variables are mostly used by VBA code I suppose.

Hello Roman,thank for your reply.I found this bit of code here at this site:

doc.MailMerge.UseNonMergeFields = true;

I want to change the value of the DocVariable in a word template from the execute

MailMerge.Execute(string[] fieldNames, object[] values);

I have had no change in the DocVariables in a test of trying to change just one.

Is there a problem in setting a DocVariable value in the word from this method or in general?

Thank you Andrew

No, you cannot change document variables using Aspose.Words merge engine

In Aspose.Words documentation it is stated that:

When UseNonMergeFields is set to true, mail merge will be performed into the following fields:

MERGEFIELD FieldName

MACROBUTTON NOMACRO FieldName

IF 0 = 0 “{FieldName}”

The list does not include document variables.

You can however access and modify document variables directly using Document.Variables property.

For example,

doc.Variables[“var1”] = “hello”;

doc.Range.UpdateFields();

You can easily write your own helper Execute(string[] fieldNames, object[] values) method on top of this functionality to do a simple merge. To imitate merge with regions using document variables will be a very complex task however.

We are considering merging other fields in our merge engine, but when it will be done I cannot say yet.

Best regards,

Hi,

Not related to DocVariables, can you provide me with a sample marked up Word document for use with UseNonMergeFields? The online documentation is very vague. I would also like to see some .NET code example for programmatic processing of this NonMergeField.

Thank you in advance,

Juan Romero

I have attached a sample word document that demonstrates the usage of non merge fields. And here is a sample code to perform MailMerge on it:

Document doc = TestUtil.Open(@“MailMerge\TestNonMergeFields.doc”);

doc.MailMerge.UseNonMergeFields = true;

doc.MailMerge.Execute(new string[] {“Field1”}, new object[] {“Value1”});

Hope this helps,

Hi

I have a similar requirement

here is the scenario. we have template created for merging data from database

on top of that… we need something like docvariable or some thing

that should prompt the user to input some information like

date to be delivered or please enter your name –

the data from database and the user inputted should be displayed on word document…

can you help me how to do that??

Hi Vijay,

Yes, Aspose.Words can achieve what you’re looking for.

Please refer to this documentation about mail merge which will help you set up merging data from a data source into a document.

You may also want to look at this documentation here, it explains about mail merge with regions which may be useful as your data is coming from a database.

You may navigate the left window for further information and examples of setting up these examples.

Regarding the prompts you need, refer to this page here for a discussion on the possible ways to include prompts in a template. You may be interested in the suggestion at the end about UserForms…

Please don’t hesitate to ask if you need further assistance.

Thanks,