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.
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.
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.
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.