Class WIfField
Represents the IF field in the document.
Inheritance
System.Object
WIfField
Inherited Members
Namespace: Syncfusion.DocIO.DLS
Assembly: Syncfusion.DocIO.Portable.dll
Syntax
public class WIfField : WField, IXDLSSerializable, IOfficeRun, IStringWidget, ISplitLeafWidget, ITextMeasurable, IWField, IWTextRange, IParagraphItem, IEntity, ILeafWidget, IWidget
Examples
The following code example demonstrates how to add an If 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("If field which uses string of characters in expression");
paragraph = section.AddParagraph();
//Create the new instance of IF field
WIfField field = paragraph.AppendField("If", FieldType.FieldIf) as WIfField;
//Specify the expression, true and false statement in field code
field.FieldCode = "IF \"True\" = \"True\" \"The given statement is Correct\" \"The given statement is Wrong\"";
paragraph = section.AddParagraph();
paragraph.AppendText("If field which uses numbers in expression");
paragraph = section.AddParagraph();
//Create the new instance of IF field
field = paragraph.AppendField("If", FieldType.FieldIf) as WIfField;
//Specify the expression, true and false statement in field code
field.FieldCode = "IF 100 >= 1000 \"The given statement is Correct\" \"The given statement is Wrong\"";
//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("If field which uses string of characters in expression")
paragraph = section.AddParagraph()
'Create the new instance of IF field
Dim field As WIfField = TryCast(paragraph.AppendField("If", FieldType.FieldIf), WIfField)
'Specify the expression, true and false statement in field code
field.FieldCode = "IF ""True"" = ""True"" ""The given statement is Correct"" ""The given statement is Wrong"""
paragraph = section.AddParagraph()
paragraph.AppendText("If field which uses numbers in expression")
paragraph = section.AddParagraph()
'Create the new instance of IF field
field = TryCast(paragraph.AppendField("If", FieldType.FieldIf), WIfField)
'Specify the expression, true and false statement in field code
field.FieldCode = "IF 100 >= 1000 ""The given statement is Correct"" ""The given statement is Wrong"""
'Update the document fields
document.UpdateDocumentFields()
document.Save("Sample.docx", FormatType.Docx)
document.Close()
End Sub
Constructors
WIfField(IWordDocument)
Initializes a new instance of the WIfField class with the specified IWordDocument instance.
Declaration
public WIfField(IWordDocument doc)
Parameters
Type | Name | Description |
---|---|---|
IWordDocument | doc | The IWordDocument instance. |
Methods
CloneImpl()
Clones itself.
Declaration
protected override object CloneImpl()
Returns
Type | Description |
---|---|
System.Object | Returns cloned object. |
Overrides
ParseFieldCode(String)
Declaration
protected override void ParseFieldCode(string fieldCode)
Parameters
Type | Name | Description |
---|---|---|
System.String | fieldCode |
Overrides
UpdateFieldCode(String)
Updates field code
Declaration
protected override void UpdateFieldCode(string fieldCode)
Parameters
Type | Name | Description |
---|---|---|
System.String | fieldCode |