当前位置: 首页>>代码示例>>C#>>正文


C# Document.SelectNodes方法代码示例

本文整理汇总了C#中Document.SelectNodes方法的典型用法代码示例。如果您正苦于以下问题:C# Document.SelectNodes方法的具体用法?C# Document.SelectNodes怎么用?C# Document.SelectNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Document的用法示例。


在下文中一共展示了Document.SelectNodes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static void Main()
        {
            // This a document that we want to add an image and custom text for each page without using the header or footer.
            Document doc = new Document(gDataDir + "TestFile.doc");

            // Create and attach collector before the document before page layout is built.
            LayoutCollector layoutCollector = new LayoutCollector(doc);

            // Images in a document are added to paragraphs, so to add an image to every page we need to find at any paragraph
            // belonging to each page.
            IEnumerator enumerator = doc.SelectNodes("//Body/Paragraph").GetEnumerator();

            // Loop through each document page.
            for (int page = 1; page <= doc.PageCount; page++)
            {
                while (enumerator.MoveNext())
                {
                    // Check if the current paragraph belongs to the target page.
                    Paragraph paragraph = (Paragraph)enumerator.Current;
                    if (layoutCollector.GetStartPageIndex(paragraph) == page)
                    {
                        AddImageToPage(paragraph, page);
                        break;
                    }
                }
            }

            doc.Save(gDataDir + "TestFile Out.docx");
        }
开发者ID:nancyeiceblue,项目名称:Aspose_Words_NET,代码行数:29,代码来源:Program.cs

示例2: ReplaceHyperlinks

        [Test] //ExSkip
        public void ReplaceHyperlinks()
        {
            // Specify your document name here.
            Document doc = new Document(MyDir + "ReplaceHyperlinks.doc");

            // Hyperlinks in a Word documents are fields, select all field start nodes so we can find the hyperlinks.
            NodeList fieldStarts = doc.SelectNodes("//FieldStart");
            foreach (FieldStart fieldStart in fieldStarts)
            {
                if (fieldStart.FieldType.Equals(FieldType.FieldHyperlink))
                {
                    // The field is a hyperlink field, use the "facade" class to help to deal with the field.
                    Hyperlink hyperlink = new Hyperlink(fieldStart);

                    // Some hyperlinks can be local (links to bookmarks inside the document), ignore these.
                    if (hyperlink.IsLocal)
                        continue;

                    // The Hyperlink class allows to set the target URL and the display name 
                    // of the link easily by setting the properties.
                    hyperlink.Target = NewUrl;
                    hyperlink.Name = NewName;
                }
            }

            doc.Save(MyDir + @"\Artifacts\ReplaceHyperlinks.doc");
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:28,代码来源:ExReplaceHyperlinks.cs

示例3: Run

        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithImages();

            // This a document that we want to add an image and custom text for each page without using the header or footer.
            Document doc = new Document(dataDir + "TestFile.doc");

            // Create and attach collector before the document before page layout is built.
            LayoutCollector layoutCollector = new LayoutCollector(doc);

            // Images in a document are added to paragraphs, so to add an image to every page we need to find at any paragraph
            // belonging to each page.
            IEnumerator enumerator = doc.SelectNodes("//Body/Paragraph").GetEnumerator();

            // Loop through each document page.
            for (int page = 1; page <= doc.PageCount; page++)
            {
                while (enumerator.MoveNext())
                {
                    // Check if the current paragraph belongs to the target page.
                    Paragraph paragraph = (Paragraph)enumerator.Current;
                    if (layoutCollector.GetStartPageIndex(paragraph) == page)
                    {
                        AddImageToPage(paragraph, page, dataDir);
                        break;
                    }
                }
            }

            doc.Save(dataDir + "TestFile Out.docx");

            Console.WriteLine("\nInserted images on each page of the document successfully.\nFile saved at " + dataDir + "TestFile Out.docx");
        }
开发者ID:robv8r,项目名称:Aspose_Words_NET,代码行数:34,代码来源:AddImageToEachPage.cs

示例4: CompositeNode_SelectNodes

        public void CompositeNode_SelectNodes()
        {
            //ExStart
            //ExFor:CompositeNode.SelectSingleNode
            //ExFor:CompositeNode.SelectNodes
            //ExSummary:Shows how to select certain nodes by using an XPath expression.
            Document doc = new Document(MyDir + "Table.Document.doc");

            // This expression will extract all paragraph nodes which are descendants of any table node in the document.
            // This will return any paragraphs which are in a table.
            NodeList nodeList = doc.SelectNodes("//Table//Paragraph");

            // This expression will select any paragraphs that are direct children of any body node in the document.
            nodeList = doc.SelectNodes("//Body/Paragraph");

            // Use SelectSingleNode to select the first result of the same expression as above.
            Node node = doc.SelectSingleNode("//Body/Paragraph");
            //ExEnd
        }
开发者ID:nausherwan-aslam,项目名称:Aspose_Words_NET,代码行数:19,代码来源:ExNode.cs

示例5: TestNodeIsInsideField

        public void TestNodeIsInsideField()
        {
            //ExStart:
            //ExFor:CompositeNode.SelectNodes
            //ExFor:CompositeNode.GetChild
            //ExSummary:Shows how to test if a node is inside a field by using an XPath expression.
            // Let's pick a document we know has some fields in.
            Document doc = new Document(MyDir + "MailMerge.MergeImage.doc");

            // Let's say we want to check if the Run below is inside a field.
            Run run = (Run)doc.GetChild(NodeType.Run, 5, true);

            // Evaluate the XPath expression. The resulting NodeList will contain all nodes found inside a field a field (between FieldStart 
            // and FieldEnd exclusive). There can however be FieldStart and FieldEnd nodes in the list if there are nested fields 
            // in the path. Currently does not find rare fields in which the FieldCode or FieldResult spans across multiple paragraphs.
            NodeList resultList = doc.SelectNodes("//FieldStart/following-sibling::node()[following-sibling::FieldEnd]");

            // Check if the specified run is one of the nodes that are inside the field.
            foreach (Node node in resultList)
            {
                if (node == run)
                {
                    Console.WriteLine("The node is found inside a field");
                    break;
                }
            }
            //ExEnd
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:28,代码来源:ExNode.cs

示例6: GetReferenceFieldContainer

 /// <summary>
 /// Gets the container for the quote field: the first paragraph in the document.
 /// </summary>
 private static CompositeNode GetReferenceFieldContainer(Document document)
 {
     return document.SelectNodes("//Body/Paragraph").OfType<Paragraph>().FirstOrDefault();
 }
开发者ID:vc3,项目名称:ExoMerge,代码行数:7,代码来源:QuoteCharacters.cs


注:本文中的Document.SelectNodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。