com.aspose.words
Class FieldBuilder

java.lang.Object
    extended by com.aspose.words.FieldBuilder

public class FieldBuilder 
extends java.lang.Object

Builds a field from field code tokens (arguments and switches).

Constructor Summary
FieldBuilder(int fieldType)
           Initializes an instance of the FieldBuilder class.
 
Method Summary
FieldBuilderaddArgument(FieldArgumentBuilder argument)
           Adds a field's argument represented by FieldArgumentBuilder to the field's code.
FieldBuilderaddArgument(FieldBuilder argument)
           Adds a child field represented by another FieldBuilder to the field's code.
FieldBuilderaddArgument(double argument)
           Adds a field's argument.
FieldBuilderaddArgument(int argument)
           Adds a field's argument.
FieldBuilderaddArgument(java.lang.String argument)
           Adds a field's argument.
FieldBuilderaddSwitch(java.lang.String switchName)
           Adds a field's switch.
FieldBuilderaddSwitch(java.lang.String switchName, double switchArgument)
           Adds a field's switch.
FieldBuilderaddSwitch(java.lang.String switchName, int switchArgument)
           Adds a field's switch.
FieldBuilderaddSwitch(java.lang.String switchName, java.lang.String switchArgument)
           Adds a field's switch.
FieldbuildAndInsert(Inline refNode)
           Builds and inserts a field into the document before the specified inline node.
FieldbuildAndInsert(Paragraph refNode)
           Builds and inserts a field into the document to the end of the specified paragraph.
 

Constructor Detail

FieldBuilder

public FieldBuilder(int fieldType)
Initializes an instance of the FieldBuilder class.
Parameters:
fieldType - A FieldType value. The type of the field to build.

Example:

Builds and inserts a field into the document before the specified inline node
Document doc = new Document();
Run run = DocumentHelper.insertNewRun(doc, " Hello World!", 0);

FieldBuilder fieldBuilder = new FieldBuilder(FieldType.FIELD_REVISION_NUM);
fieldBuilder.buildAndInsert(run);

doc.updateFields();

Method Detail

addArgument

public FieldBuilder addArgument(FieldArgumentBuilder argument)
Adds a field's argument represented by FieldArgumentBuilder to the field's code. This overload is used when the argument consists of a mixture of different parts such as child 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();

addArgument

public FieldBuilder addArgument(FieldBuilder argument)
Adds a child field represented by another FieldBuilder to the field's code. This overload is used when the argument consists of a single child field.

addArgument

public FieldBuilder addArgument(double argument)
Adds a field's argument.
Parameters:
argument - The argument value.

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();

addArgument

public FieldBuilder addArgument(int argument)
Adds a field's argument.
Parameters:
argument - The argument value.

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();

addArgument

public FieldBuilder addArgument(java.lang.String argument)
Adds a field's argument.
Parameters:
argument - The argument value.

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();

addSwitch

public FieldBuilder addSwitch(java.lang.String switchName)
Adds a field's switch. This overload adds a flag (switch without argument).
Parameters:
switchName - The switch name.

addSwitch

public FieldBuilder addSwitch(java.lang.String switchName, double switchArgument)
Adds a field's switch.
Parameters:
switchName - The switch name.
switchArgument - The switch value.

addSwitch

public FieldBuilder addSwitch(java.lang.String switchName, int switchArgument)
Adds a field's switch.
Parameters:
switchName - The switch name.
switchArgument - The switch value.

addSwitch

public FieldBuilder addSwitch(java.lang.String switchName, java.lang.String switchArgument)
Adds a field's switch.
Parameters:
switchName - The switch name.
switchArgument - The switch value.

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();

buildAndInsert

public Field buildAndInsert(Inline refNode)
                    throws java.lang.Exception
Builds and inserts a field into the document before the specified inline node.
Returns:
A Field object that represents the inserted field.

Example:

Builds and inserts a field into the document before the specified inline node
Document doc = new Document();
Run run = DocumentHelper.insertNewRun(doc, " Hello World!", 0);

FieldBuilder fieldBuilder = new FieldBuilder(FieldType.FIELD_REVISION_NUM);
fieldBuilder.buildAndInsert(run);

doc.updateFields();

buildAndInsert

public Field buildAndInsert(Paragraph refNode)
                    throws java.lang.Exception
Builds and inserts a field into the document to the end of the specified paragraph.
Returns:
A Field object that represents the inserted field.

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.