|
1 | 1 | using Syncfusion.DocIO.DLS; |
2 | 2 | using Syncfusion.DocIO; |
3 | 3 |
|
4 | | -//Register Syncfusion license |
5 | | -Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Mgo+DSMBMAY9C3t2UlhhQlNHfV5DQmBWfFN0QXNYfVRwdF9GYEwgOX1dQl9nSXZTc0VlWndfcXNSQWc="); |
6 | | - |
7 | | -using (WordDocument wordDocument = new WordDocument()) |
| 4 | +using (WordDocument document = new WordDocument()) |
8 | 5 | { |
9 | | - // Add a section and paragraph to initialize an empty document structure |
10 | | - wordDocument.EnsureMinimal(); |
| 6 | + // Add one section and one paragraph to the document. |
| 7 | + document.EnsureMinimal(); |
11 | 8 |
|
12 | | - // Append the label "Gender: Female" next to the first checkbox |
13 | | - wordDocument.LastParagraph.AppendText("Gender:\tFemale "); |
14 | | - // Append an inline content control to add a checkbox for the checked box |
15 | | - IInlineContentControl checkInline = wordDocument.LastParagraph.AppendInlineContentControl(ContentControlType.CheckBox); |
16 | 9 | // Create a CheckBoxState for the checked state, using a tick symbol in the Wingdings font |
17 | 10 | CheckBoxState tickState = new CheckBoxState |
18 | 11 | { |
19 | 12 | Font = "Wingdings", |
20 | 13 | Value = "\uF0FE" // Unicode for the tick symbol (✓) in Wingdings |
21 | 14 | }; |
22 | | - // Set the checked state of the checkbox content control to display the tick symbol when selected |
23 | | - checkInline.ContentControlProperties.CheckedState = tickState; |
24 | 15 | // Create a CheckBoxState for the unchecked state, using an empty box symbol in the Wingdings font |
25 | | - CheckBoxState uncheckedState = new CheckBoxState |
| 16 | + CheckBoxState unTickState = new CheckBoxState |
26 | 17 | { |
27 | 18 | Font = "Wingdings", |
28 | 19 | Value = "\uF0A8" // Unicode for the empty box symbol in Wingdings |
29 | 20 | }; |
| 21 | + |
| 22 | + // Gets the last paragraph. |
| 23 | + WParagraph paragraph = document.LastParagraph; |
| 24 | + // Add text to the paragraph. |
| 25 | + document.LastParagraph.AppendText("Gender:\tFemale "); |
| 26 | + // Append checkbox content control to the paragraph for the "checked" option. |
| 27 | + IInlineContentControl checkedCheckBox = document.LastParagraph.AppendInlineContentControl(ContentControlType.CheckBox); |
| 28 | + // Set the checked state of the checkbox content control to display the tick symbol when selected |
| 29 | + checkedCheckBox.ContentControlProperties.CheckedState = tickState; |
30 | 30 | // Set the unchecked state of the checkbox content control to display an empty box when not selected |
31 | | - checkInline.ContentControlProperties.UncheckedState = uncheckedState; |
| 31 | + checkedCheckBox.ContentControlProperties.UncheckedState = unTickState; |
32 | 32 | // Set the initial state of the "Female" checkbox to checked |
33 | | - checkInline.ContentControlProperties.IsChecked = true; |
| 33 | + checkedCheckBox.ContentControlProperties.IsChecked = true; |
34 | 34 |
|
35 | | - // Append a tab space and add the label "Male" for the second checkbox |
36 | | - wordDocument.LastParagraph.AppendText("\tMale "); |
37 | | - // Append an inline content control to add a checkbox for the unchecked option |
38 | | - IInlineContentControl uncheckInline = wordDocument.LastParagraph.AppendInlineContentControl(ContentControlType.CheckBox); |
| 35 | + // Gets the last paragraph. |
| 36 | + paragraph = document.LastParagraph; |
| 37 | + // Add text to the paragraph. |
| 38 | + document.LastParagraph.AppendText("\tMale "); |
| 39 | + // Append checkbox content control to the paragraph for the "unchecked" option. |
| 40 | + IInlineContentControl uncheckedCheckBox = document.LastParagraph.AppendInlineContentControl(ContentControlType.CheckBox); |
39 | 41 | // Set the checked and unchecked states. |
40 | | - uncheckInline.ContentControlProperties.CheckedState = tickState; |
41 | | - uncheckInline.ContentControlProperties.UncheckedState = uncheckedState; |
| 42 | + uncheckedCheckBox.ContentControlProperties.CheckedState = tickState; |
| 43 | + uncheckedCheckBox.ContentControlProperties.UncheckedState = unTickState; |
42 | 44 | // Set the initial state of the "Male" checkbox to unchecked |
43 | | - uncheckInline.ContentControlProperties.IsChecked = false; |
44 | | - // Save the document to a file in DOCX format |
| 45 | + uncheckedCheckBox.ContentControlProperties.IsChecked = false; |
| 46 | + |
| 47 | + // Save the document. |
45 | 48 | using (FileStream outputStream1 = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.OpenOrCreate, FileAccess.ReadWrite)) |
46 | 49 | { |
47 | | - wordDocument.Save(outputStream1, FormatType.Docx); |
| 50 | + document.Save(outputStream1, FormatType.Docx); |
48 | 51 | } |
49 | 52 | } |
0 commit comments