44//Loads an existing Word document into DocIO instance.
55using ( WordDocument document = new WordDocument ( @"../../../Data/Template.docx" ) )
66{
7- IWSection sec = document . LastSection ;
8- WTextFormField textFF ;
9- WDropDownFormField dropFF ;
7+ IWSection section = document . LastSection ;
108
11- //Access the form field with field name
12- textFF = sec . Body . FormFields [ "FullName " ] as WTextFormField ;
9+ ( section . Body . FormFields [ "FullName" ] as WTextFormField ) . TextRange . Text = "John" ;
10+ ( section . Body . FormFields [ "BirthDayField " ] as WTextFormField ) . TextRange . Text = "5.13.1980" ;
1311
14- //Fill value for the textfield
15- textFF . TextRange . Text = "John" ;
12+ ( section . Body . FormFields [ 2 ] as WTextFormField ) . TextRange . Text = "221b Baker Street" ;
13+ ( section . Body . FormFields [ 3 ] as WTextFormField ) . TextRange . Text = "(206)555-3412" ;
14+ ( section . Body . FormFields [ 4 ] as WTextFormField ) . TextRange . Text = "John@company.com" ;
1615
17- //Access the form field with field name
18- textFF = sec . Body . FormFields [ "BirthDayField" ] as WTextFormField ;
19- textFF . TextRange . Text = "5.13.1980" ;
16+ ( section . Body . FormFields [ 5 ] as WDropDownFormField ) . DropDownSelectedIndex = 1 ;
17+ ( section . Body . FormFields [ 6 ] as WTextFormField ) . TextRange . Text = "Michigan University" ;
18+ ( section . Body . FormFields [ 7 ] as WDropDownFormField ) . DropDownSelectedIndex = 1 ;
19+ ( section . Body . FormFields [ 8 ] as WDropDownFormField ) . DropDownSelectedIndex = 2 ;
2020
21- //Access the form field with index
22- textFF = sec . Body . FormFields [ 2 ] as WTextFormField ;
23- textFF . TextRange . Text = "221b Baker Street" ;
24-
25- textFF = sec . Body . FormFields [ 3 ] as WTextFormField ;
26- textFF . TextRange . Text = "(206)555-3412" ;
27-
28- textFF = sec . Body . FormFields [ 4 ] as WTextFormField ;
29- textFF . TextRange . Text = "John@company.com" ;
30-
31- dropFF = sec . Body . FormFields [ 5 ] as WDropDownFormField ;
32-
33- //Set the value
34- dropFF . DropDownSelectedIndex = 1 ;
35-
36- textFF = sec . Body . FormFields [ 6 ] as WTextFormField ;
37- textFF . TextRange . Text = "Michigan University" ;
38-
39- dropFF = sec . Body . FormFields [ 7 ] as WDropDownFormField ;
40- dropFF . DropDownSelectedIndex = 1 ;
41-
42- dropFF = sec . Body . FormFields [ 8 ] as WDropDownFormField ;
43- dropFF . DropDownSelectedIndex = 2 ;
44-
45- //Saving the document as .docx
4621 document . Save ( @"../../../Output/Sample.docx" , FormatType . Docx ) ;
4722}
0 commit comments