33using Syncfusion . Drawing ;
44
55//Create a new Word document
6- WordDocument document = new WordDocument ( ) ;
7-
8- // Add a section
9- IWSection section = document . AddSection ( ) ;
6+ using ( WordDocument document = new WordDocument ( ) )
7+ {
108
11- // Add introductory paragraph
12- IWParagraph para = section . AddParagraph ( ) ;
13- para . AppendText ( "Student Handbook\n \n " ) ;
14- para . AppendText ( "For attendance rules, see " ) ;
9+ // Add a section
10+ IWSection section = document . AddSection ( ) ;
1511
16- // Add bookmark hyperlink
17- IWField hyperlink = para . AppendHyperlink ( "Attendance" , "Attendance Policy" , HyperlinkType . Bookmark ) ;
12+ // Add introductory paragraph
13+ IWParagraph para = section . AddParagraph ( ) ;
14+ para . AppendText ( "Student Handbook\n \n " ) ;
15+ para . AppendText ( "For attendance rules, see " ) ;
1816
19- // Highlight the hyperlink text
20- WTextRange textRange = hyperlink . OwnerParagraph . ChildEntities [ hyperlink . OwnerParagraph . ChildEntities . Count - 2 ] as WTextRange ;
17+ // Add bookmark hyperlink
18+ IWField hyperlink = para . AppendHyperlink ( "Attendance" , "Attendance Policy" , HyperlinkType . Bookmark ) ;
2119
22- if ( textRange != null )
23- {
24- textRange . CharacterFormat . HighlightColor = Color . Yellow ;
25- }
20+ // Highlight the hyperlink text
21+ WTextRange textRange = hyperlink . OwnerParagraph . ChildEntities [ hyperlink . OwnerParagraph . ChildEntities . Count - 2 ] as WTextRange ;
2622
27- para . AppendText ( "." ) ;
23+ if ( textRange != null )
24+ {
25+ textRange . CharacterFormat . HighlightColor = Color . Yellow ;
26+ }
2827
29- // Add some content before the destination
30- section . AddParagraph ( ) . AppendText ( "Student Code of Conduct" ) ;
31- section . AddParagraph ( ) . AppendText ( "Examination Rules" ) ;
32- section . AddParagraph ( ) . AppendText ( "Library Guidelines" ) ;
28+ para . AppendText ( "." ) ;
3329
34- // Add bookmark destination
35- IWParagraph destination = section . AddParagraph ( ) ;
36- destination . AppendBookmarkStart ( "Attendance" ) ;
37- destination . AppendText ( "Attendance Policy" ) ;
38- destination . AppendBookmarkEnd ( "Attendance" ) ;
30+ // Add some content before the destination
31+ section . AddParagraph ( ) . AppendText ( "Student Code of Conduct" ) ;
32+ section . AddParagraph ( ) . AppendText ( "Examination Rules" ) ;
33+ section . AddParagraph ( ) . AppendText ( "Library Guidelines" ) ;
3934
40- // Add attendance rules as bullet list
41- IWParagraph bullet1 = section . AddParagraph ( ) ;
42- bullet1 . ListFormat . ApplyDefBulletStyle ( ) ;
43- bullet1 . AppendText ( "Students must maintain at least 75% attendance." ) ;
35+ // Add bookmark destination
36+ IWParagraph destination = section . AddParagraph ( ) ;
37+ destination . AppendBookmarkStart ( "Attendance" ) ;
38+ destination . AppendText ( "Attendance Policy" ) ;
39+ destination . AppendBookmarkEnd ( "Attendance" ) ;
4440
45- IWParagraph bullet2 = section . AddParagraph ( ) ;
46- bullet2 . ListFormat . ApplyDefBulletStyle ( ) ;
47- bullet2 . AppendText ( "Students should attend all mandatory classes." ) ;
41+ // Add attendance rules as bullet list
42+ IWParagraph bullet1 = section . AddParagraph ( ) ;
43+ bullet1 . ListFormat . ApplyDefBulletStyle ( ) ;
44+ bullet1 . AppendText ( "Students must maintain at least 75% attendance." ) ;
4845
49- IWParagraph bullet3 = section . AddParagraph ( ) ;
50- bullet3 . ListFormat . ApplyDefBulletStyle ( ) ;
51- bullet3 . AppendText ( "Medical leave must be supported by valid documents ." ) ;
46+ IWParagraph bullet2 = section . AddParagraph ( ) ;
47+ bullet2 . ListFormat . ApplyDefBulletStyle ( ) ;
48+ bullet2 . AppendText ( "Students should attend all mandatory classes ." ) ;
5249
53- // Save document
54- document . Save ( @"../../../Output/Output.docx" , FormatType . Docx ) ;
50+ IWParagraph bullet3 = section . AddParagraph ( ) ;
51+ bullet3 . ListFormat . ApplyDefBulletStyle ( ) ;
52+ bullet3 . AppendText ( "Medical leave must be supported by valid documents." ) ;
5553
56- // Close document
57- document . Close ( ) ;
54+ // Save document
55+ document . Save ( @"../../../Output/Output.docx" , FormatType . Docx ) ;
56+ }
0 commit comments