public void CopyToFile_Test_CopiesCorrectHyperlinksToBookmarks()
        {
            Range        range        = _application.Documents.Add().Range();
            const string bookmarkName = "bookmark1";

            Interop.Paragraph paragraph1 = range.Paragraphs.Add();
            paragraph1.Range.Text = "bookmark";
            Interop.Bookmark bookmark = paragraph1.Range.Bookmarks.Add(bookmarkName);

            range.Paragraphs.Add();
            Interop.Paragraph paragraph2 = range.Paragraphs.Add();
            paragraph2.Range.Text = "link";
            range.Hyperlinks.Add(paragraph2.Range, SubAddress: bookmark);

            _tmpFile = new OpenXmlHelper().CopyToFile(range);

            using (WordprocessingDocument doc = WordprocessingDocument.Open(_tmpFile, true)) {
                OpenXml.Body body = doc.MainDocumentPart
                                    .Document
                                    .Body;

                OpenXml.BookmarkStart bookmarkStart = body.Descendants <OpenXml.BookmarkStart>().First();
                OpenXml.Hyperlink     hyperlink     = body.Descendants <OpenXml.Hyperlink>().First();

                Assert.That(bookmarkStart.Name.Value, Is.EqualTo(bookmarkName));
                Assert.That(hyperlink.Anchor.Value, Is.EqualTo(bookmarkName));
            }
        }
Beispiel #2
0
        public void CopyToFileTextOnly_Test_DoesNotKeepHyperlinksAndBookmarks()
        {
            Range        range        = _application.Documents.Add().Range();
            const string bookmarkName = "bookmark1";

            Interop.Paragraph paragraph1 = range.Paragraphs.Add();
            paragraph1.Range.Text = "bookmark";
            Interop.Bookmark bookmark = paragraph1.Range.Bookmarks.Add(bookmarkName);

            range.Paragraphs.Add();
            Interop.Paragraph paragraph2 = range.Paragraphs.Add();
            paragraph2.Range.Text = "link";
            range.Hyperlinks.Add(paragraph2.Range, SubAddress: bookmark);

            _tmpFile = new OpenXmlHelper().CopyToFileTextOnly(range);

            using (WordprocessingDocument doc = WordprocessingDocument.Open(_tmpFile, true)) {
                OpenXml.Body body = doc.MainDocumentPart
                                    .Document
                                    .Body;

                CollectionAssert.IsEmpty(body.Descendants <OpenXml.BookmarkStart>());
                CollectionAssert.IsEmpty(body.Descendants <OpenXml.Hyperlink>());
            }
        }