public void CopyToFile_Test_CopiesCorrectHyperlinks_WithMissingBookmarks() { 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(paragraph2.Range); _application.DisplayAlerts = Interop.WdAlertLevel.wdAlertsNone; _application.Windows[1].Close(Interop.WdSaveOptions.wdDoNotSaveChanges); using (WordprocessingDocument doc = WordprocessingDocument.Open(_tmpFile, true)) { OpenXml.Hyperlink hyperlink = doc.MainDocumentPart .Document .Body .Descendants <OpenXml.Hyperlink>() .First(); Assert.That(hyperlink.Anchor.Value, Is.EqualTo(bookmarkName)); } }
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)); } }
// Generates content of footerPart1. private void GenerateFooterPart1Content(FooterPart footerPart1) { Footer footer1 = new Footer() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 w15 w16se wp14" } }; footer1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"); footer1.AddNamespaceDeclaration("cx", "http://schemas.microsoft.com/office/drawing/2014/chartex"); footer1.AddNamespaceDeclaration("cx1", "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex"); footer1.AddNamespaceDeclaration("cx2", "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex"); footer1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); footer1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office"); footer1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); footer1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math"); footer1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml"); footer1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"); footer1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"); footer1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word"); footer1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main"); footer1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml"); footer1.AddNamespaceDeclaration("w15", "http://schemas.microsoft.com/office/word/2012/wordml"); footer1.AddNamespaceDeclaration("w16se", "http://schemas.microsoft.com/office/word/2015/wordml/symex"); footer1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"); footer1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk"); footer1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml"); footer1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape"); SdtBlock sdtBlock1 = new SdtBlock(); SdtProperties sdtProperties50 = new SdtProperties(); SdtId sdtId50 = new SdtId() { Val = -1161223993 }; SdtContentDocPartObject sdtContentDocPartObject1 = new SdtContentDocPartObject(); DocPartGallery docPartGallery1 = new DocPartGallery() { Val = "Page Numbers (Bottom of Page)" }; DocPartUnique docPartUnique1 = new DocPartUnique(); sdtContentDocPartObject1.Append(docPartGallery1); sdtContentDocPartObject1.Append(docPartUnique1); sdtProperties50.Append(sdtId50); sdtProperties50.Append(sdtContentDocPartObject1); SdtEndCharProperties sdtEndCharProperties50 = new SdtEndCharProperties(); SdtContentBlock sdtContentBlock1 = new SdtContentBlock(); Paragraph paragraph369 = new Paragraph() { RsidParagraphAddition = "0094109A", RsidParagraphProperties = "00697199", RsidRunAdditionDefault = "00A563A2", ParagraphId = "3CF2B95B", TextId = "59B2ED64" }; ParagraphProperties paragraphProperties366 = new ParagraphProperties(); ParagraphStyleId paragraphStyleId26 = new ParagraphStyleId() { Val = "Footer" }; paragraphProperties366.Append(paragraphStyleId26); Hyperlink hyperlink1 = new Hyperlink() { History = true, Id = "rId1" }; Run run738 = new Run() { RsidRunProperties = "00697199", RsidRunAddition = "00697199" }; RunProperties runProperties780 = new RunProperties(); FontSize fontSize1048 = new FontSize() { Val = "20" }; FontSizeComplexScript fontSizeComplexScript1034 = new FontSizeComplexScript() { Val = "20" }; runProperties780.Append(fontSize1048); runProperties780.Append(fontSizeComplexScript1034); Text text700 = new Text(); text700.Text = "BJC IS Tech Management Standards"; run738.Append(runProperties780); run738.Append(text700); hyperlink1.Append(run738); Run run739 = new Run() { RsidRunProperties = "00697199", RsidRunAddition = "00697199" }; RunProperties runProperties781 = new RunProperties(); FontSize fontSize1049 = new FontSize() { Val = "20" }; FontSizeComplexScript fontSizeComplexScript1035 = new FontSizeComplexScript() { Val = "20" }; runProperties781.Append(fontSize1049); runProperties781.Append(fontSizeComplexScript1035); Text text701 = new Text() { Space = SpaceProcessingModeValues.Preserve }; text701.Text = " can be found at: "; run739.Append(runProperties781); run739.Append(text701); Hyperlink hyperlink2 = new Hyperlink() { History = true, Id = "rId2" }; Run run740 = new Run() { RsidRunProperties = "00697199", RsidRunAddition = "00697199" }; RunProperties runProperties782 = new RunProperties(); RunStyle runStyle2 = new RunStyle() { Val = "Hyperlink" }; FontSize fontSize1050 = new FontSize() { Val = "20" }; FontSizeComplexScript fontSizeComplexScript1036 = new FontSizeComplexScript() { Val = "20" }; runProperties782.Append(runStyle2); runProperties782.Append(fontSize1050); runProperties782.Append(fontSizeComplexScript1036); Text text702 = new Text(); text702.Text = "http://bjcis/sites/techservices/Informational%20Documents/Forms/AllItems.aspx"; run740.Append(runProperties782); run740.Append(text702); hyperlink2.Append(run740); Run run741 = new Run() { RsidRunProperties = "00697199", RsidRunAddition = "00697199" }; RunProperties runProperties783 = new RunProperties(); FontSize fontSize1051 = new FontSize() { Val = "20" }; FontSizeComplexScript fontSizeComplexScript1037 = new FontSizeComplexScript() { Val = "20" }; runProperties783.Append(fontSize1051); runProperties783.Append(fontSizeComplexScript1037); TabChar tabChar45 = new TabChar(); run741.Append(runProperties783); run741.Append(tabChar45); Run run742 = new Run() { RsidRunAddition = "00697199" }; RunProperties runProperties784 = new RunProperties(); FontSize fontSize1052 = new FontSize() { Val = "20" }; FontSizeComplexScript fontSizeComplexScript1038 = new FontSizeComplexScript() { Val = "20" }; runProperties784.Append(fontSize1052); runProperties784.Append(fontSizeComplexScript1038); Text text703 = new Text() { Space = SpaceProcessingModeValues.Preserve }; text703.Text = " "; run742.Append(runProperties784); run742.Append(text703); SdtRun sdtRun50 = new SdtRun(); SdtProperties sdtProperties51 = new SdtProperties(); RunProperties runProperties785 = new RunProperties(); FontSize fontSize1053 = new FontSize() { Val = "20" }; FontSizeComplexScript fontSizeComplexScript1039 = new FontSizeComplexScript() { Val = "20" }; runProperties785.Append(fontSize1053); runProperties785.Append(fontSizeComplexScript1039); SdtId sdtId51 = new SdtId() { Val = 860082579 }; SdtContentDocPartObject sdtContentDocPartObject2 = new SdtContentDocPartObject(); DocPartGallery docPartGallery2 = new DocPartGallery() { Val = "Page Numbers (Top of Page)" }; DocPartUnique docPartUnique2 = new DocPartUnique(); sdtContentDocPartObject2.Append(docPartGallery2); sdtContentDocPartObject2.Append(docPartUnique2); sdtProperties51.Append(runProperties785); sdtProperties51.Append(sdtId51); sdtProperties51.Append(sdtContentDocPartObject2); SdtEndCharProperties sdtEndCharProperties51 = new SdtEndCharProperties(); RunProperties runProperties786 = new RunProperties(); FontSize fontSize1054 = new FontSize() { Val = "24" }; FontSizeComplexScript fontSizeComplexScript1040 = new FontSizeComplexScript() { Val = "24" }; runProperties786.Append(fontSize1054); runProperties786.Append(fontSizeComplexScript1040); sdtEndCharProperties51.Append(runProperties786); SdtContentRun sdtContentRun50 = new SdtContentRun(); Run run743 = new Run() { RsidRunAddition = "0094109A" }; Text text704 = new Text() { Space = SpaceProcessingModeValues.Preserve }; text704.Text = "Page "; run743.Append(text704); Run run744 = new Run() { RsidRunAddition = "0094109A" }; RunProperties runProperties787 = new RunProperties(); Bold bold109 = new Bold(); BoldComplexScript boldComplexScript4 = new BoldComplexScript(); runProperties787.Append(bold109); runProperties787.Append(boldComplexScript4); FieldChar fieldChar1 = new FieldChar() { FieldCharType = FieldCharValues.Begin }; run744.Append(runProperties787); run744.Append(fieldChar1); Run run745 = new Run() { RsidRunAddition = "0094109A" }; RunProperties runProperties788 = new RunProperties(); Bold bold110 = new Bold(); BoldComplexScript boldComplexScript5 = new BoldComplexScript(); runProperties788.Append(bold110); runProperties788.Append(boldComplexScript5); FieldCode fieldCode1 = new FieldCode() { Space = SpaceProcessingModeValues.Preserve }; fieldCode1.Text = " PAGE "; run745.Append(runProperties788); run745.Append(fieldCode1); Run run746 = new Run() { RsidRunAddition = "0094109A" }; RunProperties runProperties789 = new RunProperties(); Bold bold111 = new Bold(); BoldComplexScript boldComplexScript6 = new BoldComplexScript(); runProperties789.Append(bold111); runProperties789.Append(boldComplexScript6); FieldChar fieldChar2 = new FieldChar() { FieldCharType = FieldCharValues.Separate }; run746.Append(runProperties789); run746.Append(fieldChar2); Run run747 = new Run() { RsidRunAddition = "007F6223" }; RunProperties runProperties790 = new RunProperties(); Bold bold112 = new Bold(); BoldComplexScript boldComplexScript7 = new BoldComplexScript(); NoProof noProof2 = new NoProof(); runProperties790.Append(bold112); runProperties790.Append(boldComplexScript7); runProperties790.Append(noProof2); Text text705 = new Text(); text705.Text = "1"; run747.Append(runProperties790); run747.Append(text705); Run run748 = new Run() { RsidRunAddition = "0094109A" }; RunProperties runProperties791 = new RunProperties(); Bold bold113 = new Bold(); BoldComplexScript boldComplexScript8 = new BoldComplexScript(); runProperties791.Append(bold113); runProperties791.Append(boldComplexScript8); FieldChar fieldChar3 = new FieldChar() { FieldCharType = FieldCharValues.End }; run748.Append(runProperties791); run748.Append(fieldChar3); Run run749 = new Run() { RsidRunAddition = "0094109A" }; Text text706 = new Text() { Space = SpaceProcessingModeValues.Preserve }; text706.Text = " of "; run749.Append(text706); Run run750 = new Run() { RsidRunAddition = "0094109A" }; RunProperties runProperties792 = new RunProperties(); Bold bold114 = new Bold(); BoldComplexScript boldComplexScript9 = new BoldComplexScript(); runProperties792.Append(bold114); runProperties792.Append(boldComplexScript9); FieldChar fieldChar4 = new FieldChar() { FieldCharType = FieldCharValues.Begin }; run750.Append(runProperties792); run750.Append(fieldChar4); Run run751 = new Run() { RsidRunAddition = "0094109A" }; RunProperties runProperties793 = new RunProperties(); Bold bold115 = new Bold(); BoldComplexScript boldComplexScript10 = new BoldComplexScript(); runProperties793.Append(bold115); runProperties793.Append(boldComplexScript10); FieldCode fieldCode2 = new FieldCode() { Space = SpaceProcessingModeValues.Preserve }; fieldCode2.Text = " NUMPAGES "; run751.Append(runProperties793); run751.Append(fieldCode2); Run run752 = new Run() { RsidRunAddition = "0094109A" }; RunProperties runProperties794 = new RunProperties(); Bold bold116 = new Bold(); BoldComplexScript boldComplexScript11 = new BoldComplexScript(); runProperties794.Append(bold116); runProperties794.Append(boldComplexScript11); FieldChar fieldChar5 = new FieldChar() { FieldCharType = FieldCharValues.Separate }; run752.Append(runProperties794); run752.Append(fieldChar5); Run run753 = new Run() { RsidRunAddition = "007F6223" }; RunProperties runProperties795 = new RunProperties(); Bold bold117 = new Bold(); BoldComplexScript boldComplexScript12 = new BoldComplexScript(); NoProof noProof3 = new NoProof(); runProperties795.Append(bold117); runProperties795.Append(boldComplexScript12); runProperties795.Append(noProof3); Text text707 = new Text(); text707.Text = "8"; run753.Append(runProperties795); run753.Append(text707); Run run754 = new Run() { RsidRunAddition = "0094109A" }; RunProperties runProperties796 = new RunProperties(); Bold bold118 = new Bold(); BoldComplexScript boldComplexScript13 = new BoldComplexScript(); runProperties796.Append(bold118); runProperties796.Append(boldComplexScript13); FieldChar fieldChar6 = new FieldChar() { FieldCharType = FieldCharValues.End }; run754.Append(runProperties796); run754.Append(fieldChar6); sdtContentRun50.Append(run743); sdtContentRun50.Append(run744); sdtContentRun50.Append(run745); sdtContentRun50.Append(run746); sdtContentRun50.Append(run747); sdtContentRun50.Append(run748); sdtContentRun50.Append(run749); sdtContentRun50.Append(run750); sdtContentRun50.Append(run751); sdtContentRun50.Append(run752); sdtContentRun50.Append(run753); sdtContentRun50.Append(run754); sdtRun50.Append(sdtProperties51); sdtRun50.Append(sdtEndCharProperties51); sdtRun50.Append(sdtContentRun50); paragraph369.Append(paragraphProperties366); paragraph369.Append(hyperlink1); paragraph369.Append(run739); paragraph369.Append(hyperlink2); paragraph369.Append(run741); paragraph369.Append(run742); paragraph369.Append(sdtRun50); sdtContentBlock1.Append(paragraph369); sdtBlock1.Append(sdtProperties50); sdtBlock1.Append(sdtEndCharProperties50); sdtBlock1.Append(sdtContentBlock1); Paragraph paragraph370 = new Paragraph() { RsidParagraphAddition = "0094109A", RsidParagraphProperties = "000F55C6", RsidRunAdditionDefault = "0094109A", ParagraphId = "0AAC1AD4", TextId = "7EFCA27E" }; ParagraphProperties paragraphProperties367 = new ParagraphProperties(); ParagraphStyleId paragraphStyleId27 = new ParagraphStyleId() { Val = "Footer" }; Justification justification77 = new Justification() { Val = JustificationValues.Center }; paragraphProperties367.Append(paragraphStyleId27); paragraphProperties367.Append(justification77); paragraph370.Append(paragraphProperties367); footer1.Append(sdtBlock1); footer1.Append(paragraph370); footerPart1.Footer = footer1; }