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


C# Document.GetChildNodes方法代码示例

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


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

示例1: ChangeTOCTabStops

        public void ChangeTOCTabStops()
        {
            //ExStart
            //ExFor:TabStop
            //ExFor:ParagraphFormat.TabStops
            //ExFor:Style.StyleIdentifier
            //ExFor:TabStopCollection.RemoveByPosition
            //ExFor:TabStop.Alignment
            //ExFor:TabStop.Position
            //ExFor:TabStop.Leader
            //ExId:ChangeTOCTabStops
            //ExSummary:Shows how to modify the position of the right tab stop in TOC related paragraphs.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Document.TableOfContents.doc");

            // Iterate through all paragraphs in the document
            foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
            {
                // Check if this paragraph is formatted using the TOC result based styles. This is any style between TOC and TOC9.
                if (para.ParagraphFormat.Style.StyleIdentifier >= StyleIdentifier.Toc1 && para.ParagraphFormat.Style.StyleIdentifier <= StyleIdentifier.Toc9)
                {
                    // Get the first tab used in this paragraph, this should be the tab used to align the page numbers.
                    TabStop tab = para.ParagraphFormat.TabStops[0];
                    // Remove the old tab from the collection.
                    para.ParagraphFormat.TabStops.RemoveByPosition(tab.Position);
                    // Insert a new tab using the same properties but at a modified position.
                    // We could also change the separators used (dots) by passing a different Leader type
                    para.ParagraphFormat.TabStops.Add(tab.Position - 50, tab.Alignment, tab.Leader);
                }
            }

            doc.Save(ExDir + "Document.TableOfContentsTabStops Out.doc");
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:33,代码来源:ExStyles.cs

示例2: RenameMergeFields

        public void RenameMergeFields()
        {
            // Specify your document name here.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "RenameMergeFields.doc");

            // Select all field start nodes so we can find the merge fields.
            NodeCollection fieldStarts = doc.GetChildNodes(NodeType.FieldStart, true);
            foreach (FieldStart fieldStart in fieldStarts)
            {
                if (fieldStart.FieldType.Equals(FieldType.FieldMergeField))
                {
                    MergeField mergeField = new MergeField(fieldStart);
                    mergeField.Name = mergeField.Name + "_Renamed";
                }
            }

            doc.Save(MyDir + "RenameMergeFields Out.doc");
        }
开发者ID:animaal,项目名称:Aspose_Words_NET,代码行数:18,代码来源:ExRenameMergeFields.cs

示例3: CheckShapeInline

        public void CheckShapeInline()
        {
            //ExStart
            //ExFor:ShapeBase.IsInline
            //ExSummary:Shows how to test if a shape in the document is inline or floating.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Shape.DeleteAllShapes.doc");

            foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
            {
                if(shape.IsInline)
                    Console.WriteLine("Shape is inline.");
                else
                    Console.WriteLine("Shape is floating.");
            }

            //ExEnd

            // Verify that the first shape in the document is not inline.
            Assert.False(((Shape)doc.GetChild(NodeType.Shape, 0, true)).IsInline);
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:20,代码来源:ExShape.cs

示例4: AddComment

        public void AddComment()
        {
            //ExStart
            //ExFor:Comment
            //ExFor:InlineStory
            //ExFor:InlineStory.Paragraphs
            //ExFor:InlineStory.FirstParagraph
            //ExFor:Comment.#ctor(DocumentBase, String, String, DateTime)
            //ExSummary:Shows how to add a comment to a paragraph in the document.
            Aspose.Words.Document doc = new Aspose.Words.Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.Write("Some text is added.");

            Aspose.Words.Comment comment = new Aspose.Words.Comment(doc, "Amy Lee", "AL", DateTime.Today);
            builder.CurrentParagraph.AppendChild(comment);
            comment.Paragraphs.Add(new Paragraph(doc));
            comment.FirstParagraph.Runs.Add(new Run(doc, "Comment text."));
            //ExEnd

            Assert.AreEqual("Comment text.\r", (doc.GetChildNodes(NodeType.Comment, true)[0]).GetText());
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:21,代码来源:ExInlineStory.cs

示例5: AddFootnote

        public void AddFootnote()
        {
            //ExStart
            //ExFor:Footnote
            //ExFor:InlineStory
            //ExFor:InlineStory.Paragraphs
            //ExFor:InlineStory.FirstParagraph
            //ExFor:FootnoteType
            //ExFor:Footnote.#ctor
            //ExSummary:Shows how to add a footnote to a paragraph in the document.
            Aspose.Words.Document doc = new Aspose.Words.Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.Write("Some text is added.");

            Footnote footnote = new Footnote(doc, FootnoteType.Footnote);
            builder.CurrentParagraph.AppendChild(footnote);
            footnote.Paragraphs.Add(new Paragraph(doc));
            footnote.FirstParagraph.Runs.Add(new Run(doc, "Footnote text."));
            //ExEnd

            Assert.AreEqual("Footnote text.", doc.GetChildNodes(NodeType.Footnote, true)[0].ToString(SaveFormat.Text).Trim());
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:22,代码来源:ExInlineStory.cs

示例6: Style

        public void Style()
        {
            //ExStart
            //ExFor:Font.Style
            //ExFor:Style.BuiltIn
            //ExSummary:Applies double underline to all runs in a document that are formatted with custom character styles.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Font.Style.doc");

            // Select all run nodes in the document.
            NodeCollection runs = doc.GetChildNodes(NodeType.Run, true);

            // Loop through every run node.
            foreach (Run run in runs)
            {
                Aspose.Words.Style charStyle = run.Font.Style;

                // If the style of the run is not a built-in character style, apply double underline.
                if (!charStyle.BuiltIn)
                    run.Font.Underline = Underline.Double;
            }

            doc.Save(ExDir + "Font.Style Out.doc");
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:24,代码来源:ExFont.cs

示例7: GetAllFonts

        public void GetAllFonts()
        {
            //ExStart
            //ExFor:Run
            //ExSummary:Gets all fonts used in a document.
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Font.Names.doc");

            // Select all runs in the document.
            NodeCollection runs = doc.GetChildNodes(NodeType.Run, true);

            // Use a hashtable so we will keep only unique font names.
            Hashtable fontNames = new Hashtable();

            foreach (Run run in runs)
            {
                // This adds an entry into the hashtable.
                // The key is the font name. The value is null, we don't need the value.
                fontNames[run.Font.Name] = null;
            }

            // There are two fonts used in this document.
            Console.WriteLine("Font Count: " + fontNames.Count);
            //ExEnd

            // Verify the font count is correct.
            Assert.AreEqual(2, fontNames.Count);
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:27,代码来源:ExFont.cs

示例8: JoinRunsWithSameFormatting

        public void JoinRunsWithSameFormatting()
        {
            //ExStart
            //ExFor:Document.JoinRunsWithSameFormatting
            //ExSummary:Shows how to join runs in a document to reduce unneeded runs.
            // Let's load this particular document. It contains a lot of content that has been edited many times.
            // This means the document will most likely contain a large number of runs with duplicate formatting.
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Rendering.doc");

            // This is for illustration purposes only, remember how many run nodes we had in the original document.
            int runsBefore = doc.GetChildNodes(NodeType.Run, true).Count;

            // Join runs with the same formatting. This is useful to speed up processing and may also reduce redundant
            // tags when exporting to HTML which will reduce the output file size.
            int joinCount = doc.JoinRunsWithSameFormatting();

            // This is for illustration purposes only, see how many runs are left after joining.
            int runsAfter = doc.GetChildNodes(NodeType.Run, true).Count;

            Console.WriteLine("Number of runs before:{0}, after:{1}, joined:{2}", runsBefore, runsAfter, joinCount);

            // Save the optimized document to disk.
            doc.Save(MyDir + "Document.JoinRunsWithSameFormatting Out.html");
            //ExEnd

            // Verify that runs were joined in the document.
            Assert.Less(runsAfter, runsBefore);
            Assert.AreNotEqual(0, joinCount);
        }
开发者ID:animaal,项目名称:Aspose_Words_NET,代码行数:29,代码来源:ExDocument.cs

示例9: InsertTableFromHtml

        public void InsertTableFromHtml()
        {
            //ExStart
            //ExId:InsertTableFromHtml
            //ExSummary:Shows how to insert a table in a document from a string containing HTML tags.
            Aspose.Words.Document doc = new Aspose.Words.Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert the table from HTML. Note that AutoFitSettings does not apply to tables
            // inserted from HTML.
            builder.InsertHtml("<table>"                +
                               "<tr>"                   +
                               "<td>Row 1, Cell 1</td>" +
                               "<td>Row 1, Cell 2</td>" +
                               "</tr>"                  +
                               "<tr>"                   +
                               "<td>Row 2, Cell 2</td>" +
                               "<td>Row 2, Cell 2</td>" +
                               "</tr>"                  +
                               "</table>");

            doc.Save(ExDir + "DocumentBuilder.InsertTableFromHtml Out.doc");
            //ExEnd

            // Verify the table was constructed properly.
            Assert.AreEqual(1, doc.GetChildNodes(NodeType.Table, true).Count);
            Assert.AreEqual(2, doc.GetChildNodes(NodeType.Row, true).Count);
            Assert.AreEqual(4, doc.GetChildNodes(NodeType.Cell, true).Count);
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:29,代码来源:ExDocumentBuilder.cs

示例10: InsertFootnote

        public void InsertFootnote()
        {
            //ExStart
            //ExFor:Footnote
            //ExFor:FootnoteType
            //ExFor:DocumentBuilder.InsertFootnote(FootnoteType,string)
            //ExSummary:Shows how to add a footnote to a paragraph in the document using DocumentBuilder.
            Aspose.Words.Document doc = new Aspose.Words.Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.Write("Some text");

            builder.InsertFootnote(FootnoteType.Footnote, "Footnote text.");
            //ExEnd

            Assert.AreEqual("Footnote text.", doc.GetChildNodes(NodeType.Footnote, true)[0].ToString(SaveFormat.Text).Trim());
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:16,代码来源:ExDocumentBuilder.cs

示例11: DetectBulletedParagraphs

        public void DetectBulletedParagraphs()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document();

            //ExStart
            //ExFor:Paragraph.ListFormat
            //ExFor:ListFormat.IsListItem
            //ExFor:CompositeNode.GetText
            //ExFor:List.ListId
            //ExSummary:Finds and outputs all paragraphs in a document that are bulleted or numbered.
            NodeCollection paras = doc.GetChildNodes(NodeType.Paragraph, true);
            foreach (Paragraph para in paras)
            {
                if (para.ListFormat.IsListItem)
                {
                    Console.WriteLine(string.Format("*** A paragraph belongs to list {0}", para.ListFormat.List.ListId));
                    Console.WriteLine(para.GetText());
                }
            }
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:21,代码来源:ExLists.cs

示例12: ExtractImagesToFiles

        public void ExtractImagesToFiles()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Image.SampleImages.doc");

            NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
            int imageIndex = 0;
            foreach (Shape shape in shapes)
            {
                if (shape.HasImage)
                {
                    string imageFileName = string.Format(
                        "Image.ExportImages.{0} Out{1}", imageIndex, FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType));
                    shape.ImageData.Save(ExDir + imageFileName);
                    imageIndex++;
                }
            }
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:17,代码来源:ExImage.cs

示例13: DeleteAllImagesPreOrder

        public void DeleteAllImagesPreOrder()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Image.SampleImages.doc");
            Assert.AreEqual(6, doc.GetChildNodes(NodeType.Shape, true).Count);

            //ExStart
            //ExFor:Node.NextPreOrder
            //ExSummary:Shows how to delete all images from a document using pre-order tree traversal.
            Aspose.Words.Node curNode = doc;
            while (curNode != null)
            {
                Aspose.Words.Node nextNode = curNode.NextPreOrder(doc);

                if (curNode.NodeType.Equals(NodeType.Shape))
                {
                    Shape shape = (Shape)curNode;

                    // Several shape types can have an image including image shapes and OLE objects.
                    if (shape.HasImage)
                        shape.Remove();
                }

                curNode = nextNode;
            }
            //ExEnd

            Assert.AreEqual(1, doc.GetChildNodes(NodeType.Shape, true).Count);
            doc.Save(ExDir + "Image.DeleteAllImagesPreOrder Out.doc");
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:29,代码来源:ExImage.cs

示例14: DeleteAllImages

        public void DeleteAllImages()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(ExDir + "Image.SampleImages.doc");
            Assert.AreEqual(6, doc.GetChildNodes(NodeType.Shape, true).Count);

            //ExStart
            //ExFor:Shape.HasImage
            //ExFor:Node.Remove
            //ExSummary:Shows how to delete all images from a document.
            // Here we get all shapes from the document node, but you can do this for any smaller
            // node too, for example delete shapes from a single section or a paragraph.
            NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

            // We cannot delete shape nodes while we enumerate through the collection.
            // One solution is to add nodes that we want to delete to a temporary array and delete afterwards.
            ArrayList shapesToDelete = new ArrayList();
            foreach (Shape shape in shapes)
            {
                // Several shape types can have an image including image shapes and OLE objects.
                if (shape.HasImage)
                    shapesToDelete.Add(shape);
            }

            // Now we can delete shapes.
            foreach (Shape shape in shapesToDelete)
                shape.Remove();
            //ExEnd

            Assert.AreEqual(1, doc.GetChildNodes(NodeType.Shape, true).Count);
            doc.Save(ExDir + "Image.DeleteAllImages Out.doc");
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:31,代码来源:ExImage.cs

示例15: Main


//.........这里部分代码省略.........
                            foreach (XmlNode copyNode in copyNodes)
                            {
                                string name = copyNode["Name"].InnerText;
                                string stampText = copyNode["StampText"].InnerText;
                                string flatten = copyNode["Flatten"].InnerText;
                                string outputFile = copyNode["OutputFile"].InnerText;

                                string copyValues = name + "|" + stampText + "|" + flatten + "|" + outputFile;
                                copiesList.Add(copyValues);

                            }
                            writeToLog("Copies document variables read.");
                        }
                        //---------------------------------------------------------------------------------------------------------------------------

                        //replace variables from word template with keywords and values
                        //loop through all the fields in the document and replace content with values from control xml:
                        //load word document template
                        try
                        {
                            //Read RepositoryTemplate
                            string keyword = null;
                            string value = null;
                            repositoryTemplate = repositoryTemplate.Replace("xml", "docx");
                            docTemplate = new Aspose.Words.Document(repositoryTemplate);
                            writeToLog("Document template " + docTemplate.OriginalFileName.ToString() + " loaded succesfully");
                            //--------------------------------------------------------------------------------------------------------------------------

                            if (docTemplate != null)
                            {
                                //Remove content controls/sections which will not be used
                                if (sectionsList.Count != 0)
                                {
                                    var ccntrls = docTemplate.GetChildNodes(NodeType.StructuredDocumentTag, true);
                                    foreach (var ccntrl in ccntrls)
                                    {

                                        var sdt = ccntrl as StructuredDocumentTag;
                                        var section = sdt.Title;
                                        if (!sectionsList.Contains(section))
                                        {
                                            sdt.Remove();
                                        }
                                    }
                                    writeToLog("Sections which will not be used in the document removed from template");
                                }
                                //--------------------------------------------------------------------------------------------------------------------------

                                //loop through all the fields in the document and replace content with values from control xml:
                                //replace word template variables/keywords with document values
                                if (documentKeyswordsList.Count != 0)
                                {
                                    foreach (var key in documentKeyswordsList)
                                    {
                                        //split keywords and value
                                        string[] keywordWithValues = key.Split('|');

                                        keyword = keywordWithValues[keywordWithValues.Length - 2];
                                        value = keywordWithValues[keywordWithValues.Length - 1];

                                        //loop through all the fields in the document and replace content with values from control xml:
                                        docTemplate.Range.Replace(keyword, value, false, false);
                                    }
                                    writeToLog("Document template variables replaced with document keywords and values");
                                    //---------------------------------------------------------------------------------------------------------------------------
                                 }
开发者ID:Jessy-Musyimi,项目名称:ProofOfConcept,代码行数:67,代码来源:WordDocumentProduction.cs


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