FieldBuilder Class |
Namespace: Aspose.Words.Fields
The FieldBuilder type exposes the following members.
Name | Description | |
---|---|---|
![]() ![]() | FieldBuilder |
Initializes an instance of the FieldBuilder class.
|
Name | Description | |
---|---|---|
![]() ![]() | AddArgument(Double) |
Adds a field's argument.
|
![]() ![]() | AddArgument(Int32) |
Adds a field's argument.
|
![]() ![]() | AddArgument(String) |
Adds a field's argument.
|
![]() ![]() | AddArgument(FieldArgumentBuilder) |
Adds a field's argument represented by FieldArgumentBuilder to the field's code.
|
![]() ![]() | AddArgument(FieldBuilder) |
Adds a child field represented by another FieldBuilder to the field's code.
|
![]() ![]() | AddSwitch(String) |
Adds a field's switch.
|
![]() ![]() | AddSwitch(String, Double) |
Adds a field's switch.
|
![]() ![]() | AddSwitch(String, Int32) |
Adds a field's switch.
|
![]() ![]() | AddSwitch(String, String) |
Adds a field's switch.
|
![]() ![]() | BuildAndInsert(Inline) |
Builds and inserts a field into the document before the specified inline node.
|
![]() ![]() | BuildAndInsert(Paragraph) |
Builds and inserts a field into the document to the end of the specified paragraph.
|
![]() | Equals | (Inherited from Object.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetType | (Inherited from Object.) |
![]() | ToString | (Inherited from Object.) |
Document doc = new Document(); // Use a field builder to add a SYMBOL field which displays the "F with hook" symbol FieldBuilder builder = new FieldBuilder(FieldType.FieldSymbol); builder.AddArgument(402); builder.AddSwitch("\\f", "Arial"); builder.AddSwitch("\\s", 25); builder.AddSwitch("\\u"); Field field = builder.BuildAndInsert(doc.FirstSection.Body.FirstParagraph); Assert.AreEqual(" SYMBOL 402 \\f Arial \\s 25 \\u ", field.GetFieldCode()); // Use a field builder to create a formula field that will be used by another field builder FieldBuilder innerFormulaBuilder = new FieldBuilder(FieldType.FieldFormula); innerFormulaBuilder.AddArgument(100); innerFormulaBuilder.AddArgument("+"); innerFormulaBuilder.AddArgument(74); // Add a field builder as an argument to another field builder // The result of our formula field will be used as an ANSI value representing the "enclosed R" symbol, // to be displayed by this SYMBOL field builder = new FieldBuilder(FieldType.FieldSymbol); builder.AddArgument(innerFormulaBuilder); field = builder.BuildAndInsert(doc.FirstSection.Body.AppendParagraph("")); Assert.AreEqual(" SYMBOL \u0013 = 100 + 74 \u0014\u0015 ", field.GetFieldCode()); // Now we will use our builder to construct a more complex field with nested fields // For our IF field, we will first create two formula fields to serve as expressions // Their results will be tested for equality to decide what value an IF field displays FieldBuilder leftExpression = new FieldBuilder(FieldType.FieldFormula); leftExpression.AddArgument(2); leftExpression.AddArgument("+"); leftExpression.AddArgument(3); FieldBuilder rightExpression = new FieldBuilder(FieldType.FieldFormula); rightExpression.AddArgument(2.5); rightExpression.AddArgument("*"); rightExpression.AddArgument(5.2); // Next, we will create two field arguments using field argument builders // These will serve as the two possible outputs of our IF field and they will also use our two expressions FieldArgumentBuilder trueOutput = new FieldArgumentBuilder(); trueOutput.AddText("True, both expressions amount to "); trueOutput.AddField(leftExpression); FieldArgumentBuilder falseOutput = new FieldArgumentBuilder(); falseOutput.AddNode(new Run(doc, "False, ")); falseOutput.AddField(leftExpression); falseOutput.AddNode(new Run(doc, " does not equal ")); falseOutput.AddField(rightExpression); // Finally, we will use a field builder to create an IF field which takes two field builders as expressions, // and two field argument builders as the two potential outputs builder = new FieldBuilder(FieldType.FieldIf); builder.AddArgument(leftExpression); builder.AddArgument("="); builder.AddArgument(rightExpression); builder.AddArgument(trueOutput); builder.AddArgument(falseOutput); builder.BuildAndInsert(doc.FirstSection.Body.AppendParagraph("")); doc.UpdateFields(); doc.Save(ArtifactsDir + "Field.SYMBOL.docx");