Skip to content

Commit

Permalink
Add Fields examples
Browse files Browse the repository at this point in the history
InsertMergeFieldUsingDOM
InsertMailMergeAddressBlockFieldUsingDOM
InsertAdvanceFieldWithOutDocumentBuilder
InsertASKFieldWithOutDocumentBuilder
InsertAuthorField
  • Loading branch information
naeem244 committed Feb 19, 2016
1 parent 6d944d5 commit 39d98ef
Show file tree
Hide file tree
Showing 17 changed files with 506 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Examples/CSharp/CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
<Compile Include="Programming-Documents\Document\CloningDocument.cs" />
<Compile Include="Programming-Documents\Document\AccessStyles.cs" />
<Compile Include="Programming-Documents\Fields\ChangeLocale.cs" />
<Compile Include="Programming-Documents\Fields\InsertAuthorField.cs" />
<Compile Include="Programming-Documents\Fields\InsertASKFieldWithOutDocumentBuilder.cs" />
<Compile Include="Programming-Documents\Fields\InsertAdvanceFieldWithOutDocumentBuilder.cs" />
<Compile Include="Programming-Documents\Fields\InsertMailMergeAddressBlockFieldUsingDOM.cs" />
<Compile Include="Programming-Documents\Fields\InsertMergeFieldUsingDOM.cs" />
<Compile Include="Programming-Documents\Fields\InsertField.cs" />
<Compile Include="Programming-Documents\Fields\UpdateDocFields.cs" />
<Compile Include="Programming-Documents\Tables\JoiningAndSplittingTable.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System;
using System.Collections;
using System.IO;

using Aspose.Words;
using Aspose.Words.Tables;
using Aspose.Words.Fields;
using Aspose.Words.Layout;

namespace CSharp.Programming_Documents.Working_with_Fields
{
class InsertASKFieldWithOutDocumentBuilder
{
public static void Run()
{
//ExStart:InsertASKFieldWithOutDocumentBuilder
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithFields();
Document doc = new Document(dataDir + "in.doc");
// Get paragraph you want to append this Ask field to
Paragraph para = (Paragraph)doc.GetChildNodes(NodeType.Paragraph, true)[1];

// We want to insert an Ask field like this:
// { ASK \"Test 1\" Test2 \\d Test3 \\o }

// Create instance of FieldAsk class and lets build the above field code
FieldAsk field = (FieldAsk)para.AppendField(FieldType.FieldAsk, false);

// { ASK \"Test 1\" " }
field.BookmarkName = "Test 1";

// { ASK \"Test 1\" Test2 }
field.PromptText = "Test2";

// { ASK \"Test 1\" Test2 \\d Test3 }
field.DefaultResponse = "Test3";

// { ASK \"Test 1\" Test2 \\d Test3 \\o }
field.PromptOnceOnMailMerge = true;

// Finally update this Ask field
field.Update();

dataDir = dataDir + "InsertASKFieldWithOutDocumentBuilder_out_.doc";
doc.Save(dataDir);

//ExEnd:InsertASKFieldWithOutDocumentBuilder
Console.WriteLine("\nASK field without using document builder inserted successfully.\nFile saved at " + dataDir);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections;
using System.IO;

using Aspose.Words;
using Aspose.Words.Tables;
using Aspose.Words.Fields;
using Aspose.Words.Layout;

namespace CSharp.Programming_Documents.Working_with_Fields
{
class InsertAdvanceFieldWithOutDocumentBuilder
{
public static void Run()
{
//ExStart:InsertAdvanceFieldWithOutDocumentBuilder
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithFields();
Document doc = new Document(dataDir + "in.doc");
// Get paragraph you want to append this Advance field to
Paragraph para = (Paragraph)doc.GetChildNodes(NodeType.Paragraph, true)[1];

// We want to insert an Advance field like this:
// { ADVANCE \\d 10 \\l 10 \\r -3.3 \\u 0 \\x 100 \\y 100 }

// Create instance of FieldAdvance class and lets build the above field code
FieldAdvance field = (FieldAdvance)para.AppendField(FieldType.FieldAdvance, false);


// { ADVANCE \\d 10 " }
field.DownOffset = "10";

// { ADVANCE \\d 10 \\l 10 }
field.LeftOffset = "10";

// { ADVANCE \\d 10 \\l 10 \\r -3.3 }
field.RightOffset = "-3.3";

// { ADVANCE \\d 10 \\l 10 \\r -3.3 \\u 0 }
field.UpOffset = "0";

// { ADVANCE \\d 10 \\l 10 \\r -3.3 \\u 0 \\x 100 }
field.HorizontalPosition = "100";

// { ADVANCE \\d 10 \\l 10 \\r -3.3 \\u 0 \\x 100 \\y 100 }
field.VerticalPosition = "100";

// Finally update this Advance field
field.Update();

dataDir = dataDir + "InsertAdvanceFieldWithOutDocumentBuilder_out_.doc";
doc.Save(dataDir);

//ExEnd:InsertAdvanceFieldWithOutDocumentBuilder
Console.WriteLine("\nAdvance field without using document builder inserted successfully.\nFile saved at " + dataDir);
}
}
}
41 changes: 41 additions & 0 deletions Examples/CSharp/Programming-Documents/Fields/InsertAuthorField.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections;
using System.IO;

using Aspose.Words;
using Aspose.Words.Tables;
using Aspose.Words.Fields;
using Aspose.Words.Layout;

namespace CSharp.Programming_Documents.Working_with_Fields
{
class InsertAuthorField
{
public static void Run()
{
//ExStart:InsertAuthorField
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithFields();
Document doc = new Document(dataDir + "in.doc");
// Get paragraph you want to append this AUTHOR field to
Paragraph para = (Paragraph)doc.GetChildNodes(NodeType.Paragraph, true)[1];

// We want to insert an AUTHOR field like this:
// { AUTHOR Test1 }

// Create instance of FieldAuthor class and lets build the above field code
FieldAuthor field = (FieldAuthor)para.AppendField(FieldType.FieldAuthor, false);

// { AUTHOR Test1 }
field.AuthorName = "Test1";

// Finally update this AUTHOR field
field.Update();

dataDir = dataDir + "InsertAuthorField_out_.doc";
doc.Save(dataDir);
//ExEnd:InsertAuthorField
Console.WriteLine("\nAuthor field without document builder inserted successfully.\nFile saved at " + dataDir);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections;
using System.IO;

using Aspose.Words;
using Aspose.Words.Tables;
using Aspose.Words.Fields;
using Aspose.Words.Layout;

namespace CSharp.Programming_Documents.Working_with_Fields
{
class InsertMailMergeAddressBlockFieldUsingDOM
{
public static void Run()
{
//ExStart:InsertMailMergeAddressBlockFieldUsingDOM
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithFields();
Document doc = new Document(dataDir + "in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);

// Get paragraph you want to append this merge field to
Paragraph para = (Paragraph)doc.GetChildNodes(NodeType.Paragraph, true)[1];

// Move cursor to this paragraph
builder.MoveTo(para);

// We want to insert a mail merge address block like this:
// { ADDRESSBLOCK \\c 1 \\d \\e Test2 \\f Test3 \\l \"Test 4\" }

// Create instance of FieldAddressBlock class and lets build the above field code
FieldAddressBlock field = (FieldAddressBlock)builder.InsertField(FieldType.FieldAddressBlock, false);

// { ADDRESSBLOCK \\c 1" }
field.IncludeCountryOrRegionName = "1";

// { ADDRESSBLOCK \\c 1 \\d" }
field.FormatAddressOnCountryOrRegion = true;

// { ADDRESSBLOCK \\c 1 \\d \\e Test2 }
field.ExcludedCountryOrRegionName = "Test2";

// { ADDRESSBLOCK \\c 1 \\d \\e Test2 \\f Test3 }
field.NameAndAddressFormat = "Test3";

// { ADDRESSBLOCK \\c 1 \\d \\e Test2 \\f Test3 \\l \"Test 4\" }
field.LanguageId = "Test 4";

// Finally update this merge field
field.Update();

dataDir = dataDir + "InsertMailMergeAddressBlockFieldUsingDOM_out_.doc";
doc.Save(dataDir);

//ExEnd:InsertMailMergeAddressBlockFieldUsingDOM
Console.WriteLine("\nMail Merge address block field using DOM inserted successfully.\nFile saved at " + dataDir);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections;
using System.IO;

using Aspose.Words;
using Aspose.Words.Tables;
using Aspose.Words.Fields;
using Aspose.Words.Layout;

namespace CSharp.Programming_Documents.Working_with_Fields
{
class InsertMergeFieldUsingDOM
{
public static void Run()
{
//ExStart:InsertMergeFieldUsingDOM
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithFields();
Document doc = new Document(dataDir + "in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);

// Get paragraph you want to append this merge field to
Paragraph para = (Paragraph)doc.GetChildNodes(NodeType.Paragraph, true)[1];

// Move cursor to this paragraph
builder.MoveTo(para);

// We want to insert a merge field like this:
// { " MERGEFIELD Test1 \\b Test2 \\f Test3 \\m \\v" }

// Create instance of FieldMergeField class and lets build the above field code
FieldMergeField field = (FieldMergeField)builder.InsertField(FieldType.FieldMergeField, false);

// { " MERGEFIELD Test1" }
field.FieldName = "Test1";

// { " MERGEFIELD Test1 \\b Test2" }
field.TextBefore = "Test2";

// { " MERGEFIELD Test1 \\b Test2 \\f Test3 }
field.TextAfter = "Test3";

// { " MERGEFIELD Test1 \\b Test2 \\f Test3 \\m" }
field.IsMapped = true;

// { " MERGEFIELD Test1 \\b Test2 \\f Test3 \\m \\v" }
field.IsVerticalFormatting = true;

// Finally update this merge field
field.Update();

dataDir = dataDir + "InsertMergeFieldUsingDOM_out_.doc";
doc.Save(dataDir);

//ExEnd:InsertMergeFieldUsingDOM
Console.WriteLine("\nMerge field using DOM inserted successfully.\nFile saved at " + dataDir);
}
}
}
5 changes: 5 additions & 0 deletions Examples/CSharp/RunExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public static void Main()
//ChangeLocale.Run();
//UpdateDocFields.Run();
//InsertField.Run();
//InsertMergeFieldUsingDOM.Run();
//InsertMailMergeAddressBlockFieldUsingDOM.Run();
//InsertAdvanceFieldWithOutDocumentBuilder.Run();
//InsertASKFieldWithOutDocumentBuilder.Run();
InsertAuthorField.Run();

//// Images
//// =====================================================
Expand Down
Binary file not shown.
Binary file not shown.
Binary file added Examples/Data/Programming-Documents/Fields/in.doc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Imports Microsoft.VisualBasic
Imports System.IO
Imports Aspose.Words
Imports Aspose.Words.Fields
Public Class InsertASKFieldWithOutDocumentBuilder
Public Shared Sub Run()
' ExStart:InsertASKFieldWithOutDocumentBuilder
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields()
Dim doc As New Document(dataDir & Convert.ToString("in.doc"))
' Get paragraph you want to append this Ask field to
Dim para As Paragraph = DirectCast(doc.GetChildNodes(NodeType.Paragraph, True)(1), Paragraph)

' We want to insert an Ask field like this:
' { ASK \"Test 1\" Test2 \\d Test3 \\o }

' Create instance of FieldAsk class and lets build the above field code
Dim field As FieldAsk = DirectCast(para.AppendField(FieldType.FieldAsk, False), FieldAsk)

' { ASK \"Test 1\" " }
field.BookmarkName = "Test 1"

' { ASK \"Test 1\" Test2 }
field.PromptText = "Test2"

' { ASK \"Test 1\" Test2 \\d Test3 }
field.DefaultResponse = "Test3"

' { ASK \"Test 1\" Test2 \\d Test3 \\o }
field.PromptOnceOnMailMerge = True

' Finally update this Ask field
field.Update()

dataDir = dataDir & Convert.ToString("InsertASKFieldWithOutDocumentBuilder_out_.doc")
doc.Save(dataDir)

' ExEnd:InsertASKFieldWithOutDocumentBuilder
Console.WriteLine(Convert.ToString(vbLf & "ASK field without using document builder inserted successfully." & vbLf & "File saved at ") & dataDir)
End Sub
End Class
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Imports Microsoft.VisualBasic
Imports System.IO
Imports Aspose.Words
Imports Aspose.Words.Fields
Public Class InsertAdvanceFieldWithOutDocumentBuilder
Public Shared Sub Run()
' ExStart:InsertAdvanceFieldWithOutDocumentBuilder
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_WorkingWithFields()
Dim doc As New Document(dataDir & Convert.ToString("in.doc"))
' Get paragraph you want to append this Advance field to
Dim para As Paragraph = DirectCast(doc.GetChildNodes(NodeType.Paragraph, True)(1), Paragraph)

' We want to insert an Advance field like this:
' { ADVANCE \\d 10 \\l 10 \\r -3.3 \\u 0 \\x 100 \\y 100 }

' Create instance of FieldAdvance class and lets build the above field code
Dim field As FieldAdvance = DirectCast(para.AppendField(FieldType.FieldAdvance, False), FieldAdvance)


' { ADVANCE \\d 10 " }
field.DownOffset = "10"

' { ADVANCE \\d 10 \\l 10 }
field.LeftOffset = "10"

' { ADVANCE \\d 10 \\l 10 \\r -3.3 }
field.RightOffset = "-3.3"

' { ADVANCE \\d 10 \\l 10 \\r -3.3 \\u 0 }
field.UpOffset = "0"

' { ADVANCE \\d 10 \\l 10 \\r -3.3 \\u 0 \\x 100 }
field.HorizontalPosition = "100"

' { ADVANCE \\d 10 \\l 10 \\r -3.3 \\u 0 \\x 100 \\y 100 }
field.VerticalPosition = "100"

' Finally update this Advance field
field.Update()

dataDir = dataDir & Convert.ToString("InsertAdvanceFieldWithOutDocumentBuilder_out_.doc")
doc.Save(dataDir)

' ExEnd:InsertAdvanceFieldWithOutDocumentBuilder
Console.WriteLine(Convert.ToString(vbLf & "Advance field without using document builder inserted successfully." & vbLf & "File saved at ") & dataDir)
End Sub
End Class
Loading

0 comments on commit 39d98ef

Please sign in to comment.