Exemplo n.º 1
0
        public static void AddBookmark()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            builder.InsertLine("First paragraph in this document.");

            //Insert some content before bookmark
            builder.InsertText("Second paragraph start. ");
            //Select the content you want to bookmark
            TextInline textBookmark = builder.InsertText("This is bookmark. ");

            //Insert some content after bookmark
            builder.InsertText("Second paragraph end.");

            //Add bookmark with selected content
            builder.InsertBookmark("bookmark1", textBookmark, textBookmark);

            WordFile wordFile = new WordFile();

            using (var stream = File.OpenWrite("AddBookmark.docx"))
            {
                wordFile.Export(document, stream);
            }
        }
Exemplo n.º 2
0
        public static void AddLinkInsideDocument()
        {
            WordDocument        document = new WordDocument();
            WordDocumentBuilder builder  = new WordDocumentBuilder(document);

            //Add hyperlink navigate to bookmark inside this document by bookmark's name
            builder.InsertHyperlinkToBookmark("this is hyerlink", "bookmark1", "go to bookmark1");

            //Add a bookmark in the second page
            builder.InsertBreak(BreakType.PageBreak);
            TextInline textBookmark = builder.InsertText("This is bookmark1. ");

            builder.InsertBookmark("bookmark1", textBookmark, textBookmark);

            WordFile wordFile = new WordFile();

            using (var stream = File.OpenWrite("AddLinkInsideDocument.docx"))
            {
                wordFile.Export(document, stream);
            }
        }