[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
    Supported Formats
   [Expand]Getting Started
   [Expand]RichEditControl Document
   [Collapse]Fields
    [Collapse]Field Codes
      AUTHOR
      COMMENTS
      CREATEDATE
      DATE
      DOCPROPERTY
      DOCVARIABLE
      HYPERLINK
      IF
      INCLUDEPICTURE
      KEYWORDS
      LASTSAVEDBY
      MERGEFIELD
      NUMPAGES
      PAGE
      PRINTDATE
      REVNUM
      SAVEDATE
      SEQ
      SUBJECT
      SYMBOL
      TC
      TIME
      TITLE
      TOC
    [Expand]Format Switches
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Printing
    AutoCorrect
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
    Traversing the Document
   [Expand]Visual Elements
    Services
    Events
    Commands
    HTML Tag Support
   [Expand]Examples
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

DOCVARIABLE

DOCVARIABLE

Mixed field

{ DOCVARIABLE "variable name" "argument1" "argument 2"... }

Inserts the value of a document variable specified by a text in field argument. Document variables are contained in the DocumentVariableCollection collection object, accessible via the Document.Variables property. Before a field is updated, the Document.CalculateDocumentVariable event is fired allowing you to manually calculate the required value. The CalculateDocumentVariableEventArgs.Arguments provides access to a collection of arguments contained within the field.

Note

You can return a text or the entire IRichEditDocumentServer.Document as a document variable.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E3914.

A common task is to evaluate DOCVARIABLE fields in a document depending on the variable name and argument and then substitute fields with their values. The resulting document no longer contains fields and its content is fixed. To accomplish this task, you can use two RichEditDocumentServer instances - the first instance loads a document and calls the MailMerge method, the second instance handles the IRichEditDocumentServer.CalculateDocumentVariable event. The code

produces the final document in the richEditDocumentServer2 instance. Since MailMerge requires a data source for successful execution, you should provide a fake data source. It may be as simple as a collection exposing the System.Collections.IList interface and containing one item.

If a field is locked (the Field.Locked property is true), the field cannot be updated by the Field.Update or FieldCollection.Update methods and by executing UI commands. The Document.CalculateDocumentVariable event is not raised for a locked field and it retains its previous value. However, you can set the FieldOptions.UpdateLockedFields option to change default actions for locked fields.

You can specify whether the DOCVARIABLE fields are updated before printing or copying a range to the clipboard. Use the FieldOptions.UpdateDocVariablesBeforeCopy, Document.UpdateDocVariablesBeforePrint or the FieldOptions.UpdateDocVariablesBeforePrint option.

Is this topic helpful?​​​​​​​