Class DocVariables
Represents the Word document variables.
Inheritance
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.NET.dll
Syntax
public class DocVariables : Object
Examples
The following code snippet illustrate how to add a DocVariable field in Word document.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
WordDocument document = new WordDocument();
IWSection section = document.AddSection();
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendText("First Name of the customer: ");
//Add the DocVariable field with Variable name and its type
paragraph.AppendField("FirstName", FieldType.FieldDocVariable);
paragraph = section.AddParagraph();
paragraph.AppendText("Last Name of the customer: ");
//Add the DocVariable field with Variable name and its type
paragraph.AppendField("LastName", FieldType.FieldDocVariable);
//Add the value for variable in WordDocument.Variable collection
document.Variables.Add("FirstName", "Jeff");
document.Variables.Add("LastName", "Smith");
//Update the document fields
document.UpdateDocumentFields();
document.Save("Sample.docx", FormatType.Docx);
document.Close();
}
Private Sub button_Click(sender As Object, e As EventArgs)
Dim document As New WordDocument()
Dim section As IWSection = document.AddSection()
Dim paragraph As IWParagraph = section.AddParagraph()
paragraph.AppendText("First Name of the customer: ")
'Add the DocVariable field with Variable name and its type
paragraph.AppendField("FirstName", FieldType.FieldDocVariable)
paragraph = section.AddParagraph()
paragraph.AppendText("Last Name of the customer: ")
'Add the DocVariable field with Variable name and its type
paragraph.AppendField("LastName", FieldType.FieldDocVariable)
'Add the value for variable in WordDocument.Variable collection
document.Variables.Add("FirstName", "Jeff")
document.Variables.Add("LastName", "Smith")
'Update the document fields
document.UpdateDocumentFields()
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Constructors
DocVariables()
Initializes a new instance of the DocVariables class.
Declaration
public DocVariables()
Properties
Count
Gets the count of variables.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The integer that specifies the variables count. |
Item[String]
Gets or sets the variable with the specified name.
Declaration
public string this[string name] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The string that specifies the name of the variable. |
Property Value
Type | Description |
---|---|
System.String | The string that represents the variable name. |
Methods
Add(String, String)
Adds new document variable to document.
Declaration
public void Add(string name, string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The string that specifies the varaible name. |
System.String | value | The string that specifies the varaible value. |
GetNameByIndex(Int32)
Gets variable's key by its index.
Declaration
public string GetNameByIndex(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The integer that specifies the index of the variable. |
Returns
Type | Description |
---|---|
System.String | The string that represents the key of the variable. |
GetValueByIndex(Int32)
Gets variable's value by the index.
Declaration
public string GetValueByIndex(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The integer that specifies the index of the variable. |
Returns
Type | Description |
---|---|
System.String | The string that represents the value of the variable. |
Remove(String)
Removes document variable with specified name from the document.
Declaration
public void Remove(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The string that represents the name of the variable. |