public void GetFieldNames() { //ExStart //ExFor:FieldAddressBlock //ExFor:FieldAddressBlock.GetFieldNames //ExSummary:Shows how to get mail merge field names used by the field Document doc = new Document(MyDir + "MailMerge.GetFieldNames.docx"); string[] addressFieldsExpect = { "Company", "First Name", "Middle Name", "Last Name", "Suffix", "Address 1", "City", "State", "Country or Region", "Postal Code" }; FieldAddressBlock addressBlockField = (FieldAddressBlock)doc.Range.Fields[0]; string[] addressBlockFieldNames = addressBlockField.GetFieldNames(); //ExEnd Assert.AreEqual(addressFieldsExpect, addressBlockFieldNames); string[] greetingFieldsExpect = { "Courtesy Title", "Last Name" }; FieldGreetingLine greetingLineField = (FieldGreetingLine)doc.Range.Fields[1]; string[] greetingLineFieldNames = greetingLineField.GetFieldNames(); Assert.AreEqual(greetingFieldsExpect, greetingLineFieldNames); }
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); }
public void FieldAddressBlock() { //ExStart //ExFor:Fields.FieldAddressBlock.ExcludedCountryOrRegionName //ExFor:Fields.FieldAddressBlock.FormatAddressOnCountryOrRegion //ExFor:Fields.FieldAddressBlock.IncludeCountryOrRegionName //ExFor:Fields.FieldAddressBlock.LanguageId //ExFor:Fields.FieldAddressBlock.NameAndAddressFormat //ExSummary:Shows how to build a field address block. Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Use a document builder to insert a field address block FieldAddressBlock field = (FieldAddressBlock)builder.InsertField(FieldType.FieldAddressBlock, true); // Initially our field is an empty address block field with null attributes Assert.AreEqual(" ADDRESSBLOCK ", field.GetFieldCode()); // Setting this to "2" will cause all countries/regions to be included, unless it is the one specified in the ExcludedCountryOrRegionName attribute field.IncludeCountryOrRegionName = "2"; field.FormatAddressOnCountryOrRegion = true; field.ExcludedCountryOrRegionName = "United States"; // Specify our own name and address format field.NameAndAddressFormat = "<Title> <Forename> <Surname> <Address Line 1> <Region> <Postcode> <Country>"; // By default, the language ID will be set to that of the first character of the document // In this case we will specify it to be English field.LanguageId = "1033"; // Our field code has changed according to the attribute values that we set Assert.AreEqual( " ADDRESSBLOCK \\c 2 \\d \\e \"United States\" \\f \"<Title> <Forename> <Surname> <Address Line 1> <Region> <Postcode> <Country>\" \\l 1033", field.GetFieldCode()); //ExEnd Assert.AreEqual("2", field.IncludeCountryOrRegionName); Assert.AreEqual(true, field.FormatAddressOnCountryOrRegion); Assert.AreEqual("United States", field.ExcludedCountryOrRegionName); Assert.AreEqual("<Title> <Forename> <Surname> <Address Line 1> <Region> <Postcode> <Country>", field.NameAndAddressFormat); Assert.AreEqual("1033", field.LanguageId); }
public void GetFieldNames() { Document doc = new Document(MyDir + "MailMerge.GetFieldNames.docx"); string[] addressFieldsExpect = { "Company", "First Name", "Middle Name", "Last Name", "Suffix", "Address 1", "City", "State", "Country or Region", "Postal Code" }; FieldAddressBlock addressBlockField = (FieldAddressBlock)doc.Range.Fields[0]; string[] addressBlockFieldNames = addressBlockField.GetFieldNames(); Assert.AreEqual(addressFieldsExpect, addressBlockFieldNames); string[] greetingFieldsExpect = { "Courtesy Title", "Last Name" }; FieldGreetingLine greetingLineField = (FieldGreetingLine)doc.Range.Fields[1]; string[] greetingLineFieldNames = greetingLineField.GetFieldNames(); Assert.AreEqual(greetingFieldsExpect, greetingLineFieldNames); }