com.aspose.words

Class FieldArgumentBuilder

  • java.lang.Object
    • com.aspose.words.FieldArgumentBuilder
public class FieldArgumentBuilder 
extends java.lang.Object

Builds a complex field argument consisting of fields, nodes, and plain text.

Example:

Inserts a field into a document using field builder constructor
Document doc = new Document();

//Add text into the paragraph
Paragraph para = doc.getFirstSection().getBody().getParagraphs().get(0);
Run run = new Run(doc);
{
    run.setText(" Hello World!");
}
para.appendChild(run);

FieldArgumentBuilder argumentBuilder = new FieldArgumentBuilder();
argumentBuilder.addField(new FieldBuilder(FieldType.FIELD_MERGE_FIELD));
argumentBuilder.addText("BestField");

FieldBuilder fieldBuilder = new FieldBuilder(FieldType.FIELD_IF);
fieldBuilder.addArgument(argumentBuilder).addArgument("=").addArgument("BestField").addArgument(10).addArgument(20.0).addSwitch("12", "13").buildAndInsert(run);

doc.updateFields();

Constructor Summary
FieldArgumentBuilder()
Initializes an instance of the FieldArgumentBuilder class.
 
Method Summary
FieldArgumentBuilderaddField(FieldBuilder fieldBuilder)
Adds a field represented by a FieldBuilder to the argument.
FieldArgumentBuilderaddNode(Inline node)
Adds a node to the argument.
FieldArgumentBuilderaddText(java.lang.String text)
Adds a plain text to the argument.
 

    • Constructor Detail

      • FieldArgumentBuilder

        public FieldArgumentBuilder()
        Initializes an instance of the FieldArgumentBuilder class.
    • Method Detail

      • addField

        public FieldArgumentBuilder addField(FieldBuilder fieldBuilder)
        Adds a field represented by a FieldBuilder to the argument.

        Example:

        Inserts a field into a document using field builder constructor
        Document doc = new Document();
        
        //Add text into the paragraph
        Paragraph para = doc.getFirstSection().getBody().getParagraphs().get(0);
        Run run = new Run(doc);
        {
            run.setText(" Hello World!");
        }
        para.appendChild(run);
        
        FieldArgumentBuilder argumentBuilder = new FieldArgumentBuilder();
        argumentBuilder.addField(new FieldBuilder(FieldType.FIELD_MERGE_FIELD));
        argumentBuilder.addText("BestField");
        
        FieldBuilder fieldBuilder = new FieldBuilder(FieldType.FIELD_IF);
        fieldBuilder.addArgument(argumentBuilder).addArgument("=").addArgument("BestField").addArgument(10).addArgument(20.0).addSwitch("12", "13").buildAndInsert(run);
        
        doc.updateFields();
      • addNode

        public FieldArgumentBuilder addNode(Inline node)
        Adds a node to the argument. Only text level nodes are supported at the moment.
      • addText

        public FieldArgumentBuilder addText(java.lang.String text)
        Adds a plain text to the argument.

        Example:

        Inserts a field into a document using field builder constructor
        Document doc = new Document();
        
        //Add text into the paragraph
        Paragraph para = doc.getFirstSection().getBody().getParagraphs().get(0);
        Run run = new Run(doc);
        {
            run.setText(" Hello World!");
        }
        para.appendChild(run);
        
        FieldArgumentBuilder argumentBuilder = new FieldArgumentBuilder();
        argumentBuilder.addField(new FieldBuilder(FieldType.FIELD_MERGE_FIELD));
        argumentBuilder.addText("BestField");
        
        FieldBuilder fieldBuilder = new FieldBuilder(FieldType.FIELD_IF);
        fieldBuilder.addArgument(argumentBuilder).addArgument("=").addArgument("BestField").addArgument(10).addArgument(20.0).addSwitch("12", "13").buildAndInsert(run);
        
        doc.updateFields();