|
| 1 | +using Syncfusion.DocIO; |
| 2 | +using Syncfusion.DocIO.DLS; |
| 3 | +using System.IO; |
| 4 | + |
| 5 | +namespace Control_bookmark_end_position |
| 6 | +{ |
| 7 | + class Program |
| 8 | + { |
| 9 | + static void Main(string[] args) |
| 10 | + { |
| 11 | + //Creates an instance of WordDocument class (Empty Word Document). |
| 12 | + using (WordDocument document = new WordDocument()) |
| 13 | + { |
| 14 | + //Adds a section to the document. |
| 15 | + IWSection section = document.AddSection(); |
| 16 | + //Adds a paragraph and preserves the bookmark end after the paragraph mark. |
| 17 | + IWParagraph paragraph = section.AddParagraph(); |
| 18 | + paragraph.AppendBookmarkStart("ParagraphBookmark"); |
| 19 | + paragraph.AppendText("Paragraph bookmark"); |
| 20 | + BookmarkEnd bookmarkEnd = paragraph.AppendBookmarkEnd("ParagraphBookmark"); |
| 21 | + bookmarkEnd.IsAfterParagraphMark = true; |
| 22 | + //Adds a 2 x 2 table. |
| 23 | + IWTable table = section.AddTable(); |
| 24 | + table.ResetCells(2, 2); |
| 25 | + //Adds a bookmark end after the table-cell mark of the first cell. |
| 26 | + IWParagraph cellParagraph = table[0, 0].AddParagraph(); |
| 27 | + cellParagraph.AppendBookmarkStart("CellBookmark"); |
| 28 | + cellParagraph.AppendText("Cell bookmark"); |
| 29 | + bookmarkEnd = cellParagraph.AppendBookmarkEnd("CellBookmark"); |
| 30 | + bookmarkEnd.IsAfterCellMark = true; |
| 31 | + //Adds a bookmark end after the first table-row mark, in the final cell of that row. |
| 32 | + IWParagraph rowParagraph = table[0, 1].AddParagraph(); |
| 33 | + rowParagraph.AppendBookmarkStart("RowBookmark"); |
| 34 | + rowParagraph.AppendText("Row bookmark"); |
| 35 | + bookmarkEnd = rowParagraph.AppendBookmarkEnd("RowBookmark"); |
| 36 | + bookmarkEnd.IsAfterRowMark = true; |
| 37 | + //Adds content to the remaining cell without a bookmark end. |
| 38 | + table[1, 0].AddParagraph().AppendText("Content"); |
| 39 | + //Adds a bookmark end after the table mark, in the final cell of the final row. |
| 40 | + IWParagraph tableParagraph = table[1, 1].AddParagraph(); |
| 41 | + tableParagraph.AppendBookmarkStart("TableBookmark"); |
| 42 | + tableParagraph.AppendText("Table bookmark"); |
| 43 | + bookmarkEnd = tableParagraph.AppendBookmarkEnd("TableBookmark"); |
| 44 | + bookmarkEnd.IsAfterTableMark = true; |
| 45 | + //Creates file stream. |
| 46 | + using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/BookmarkEndPositions.docx"), FileMode.Create, FileAccess.ReadWrite)) |
| 47 | + { |
| 48 | + //Saves the Word document to file stream. |
| 49 | + document.Save(outputFileStream, FormatType.Docx); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments