public void CopyFromFile_Test_CopiesCorrectHyperlinksToBookmarks() { _tmpFile = GetNewRandomFilePath(GetOrCreateTmpDirectory()); using (DocX doc = DocX.Create(_tmpFile)) { Hyperlink hyperlink = doc.AddHyperlink("hypelink text", "bookmark"); doc.InsertParagraph() .AppendBookmark("bookmark") .Append("bookmark text"); doc.InsertParagraph() .AppendHyperlink(hyperlink); doc.Save(); } Range targetRange = _application.Documents.Add().Range(); targetRange.Text = "unexpected"; new OpenXmlHelper().CopyFromFile(_tmpFile, targetRange); Bookmarks bookmarks = targetRange.Document.Bookmarks; Hyperlinks hyperlinks = targetRange.Document.Hyperlinks; Assert.NotZero(bookmarks.Count); Assert.NotZero(hyperlinks.Count); Assert.That(hyperlinks[1].SubAddress, Is.EqualTo(bookmarks[1].Name)); }
public void CopyFromFile_Test_CopiesNoHyperlinksToBookmarks() { _tmpFile = GetNewRandomFilePath(GetOrCreateTmpDirectory()); using (DocX doc = DocX.Create(_tmpFile)) { Hyperlink hyperlink = doc.AddHyperlink("hypelink text", "bookmark"); doc.InsertParagraph() .AppendBookmark("bookmark") .Append("bookmark text"); doc.InsertParagraph() .AppendHyperlink(hyperlink); doc.Save(); } Range targetRange = _application.Documents.Add().Range(); targetRange.Text = "unexpected"; new OpenXmlHelper().CopyFromFileTextOnly(_tmpFile, targetRange); Assert.Zero(targetRange.Document.Bookmarks.Count); Assert.Zero(targetRange.Document.Hyperlinks.Count); }