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


C# Document.GetChildNodes方法代码示例

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


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

示例1: Iso29500Strict

        public void Iso29500Strict()
        {
            //ExStart
            //ExFor:OoxmlCompliance.Iso29500_2008_Strict
            //ExSummary:Shows conversion vml shapes to dml using Iso29500_2008_Strict option
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            //Set Word2003 version for document, for inserting image as vml shape
            doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2003);
            
            Shape image = builder.InsertImage(MyDir + @"dotnet-logo.png");

            // Loop through all single shapes inside document.
            foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
            {
                Assert.AreEqual(ShapeMarkupLanguage.Vml, shape.MarkupLanguage);
            }

            OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
            saveOptions.Compliance = OoxmlCompliance.Iso29500_2008_Strict; //Iso29500_2008 does not allow vml shapes, so you need to use OoxmlCompliance.Iso29500_2008_Strict for converting vml to dml shapes
            saveOptions.SaveFormat = SaveFormat.Docx;

            MemoryStream dstStream = new MemoryStream();
            doc.Save(dstStream, saveOptions);

            //Assert that image have drawingML markup language
            foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
            {
                Assert.AreEqual(ShapeMarkupLanguage.Dml, shape.MarkupLanguage);
            }
            //ExEnd
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:33,代码来源:ExOoxmlSaveOptions.cs

示例2: Run

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

            // Load the documents which store the shapes we want to render.           
            Document doc = new Document(dataDir + "ActiveXControl.docx");

            string properties = "";
            // Retrieve shapes from the document.         
            foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
            {
                OleControl oleControl = shape.OleFormat.OleControl;               
                if (oleControl.IsForms2OleControl)
                {
                    Forms2OleControl checkBox = (Forms2OleControl)oleControl;
                    properties = properties + "\nCaption: " + checkBox.Caption;
                    properties = properties + "\nValue: " + checkBox.Value;
                    properties = properties + "\nEnabled: " + checkBox.Enabled;
                    properties = properties + "\nType: " + checkBox.Type;
                    if (checkBox.ChildNodes != null)
                    {
                        properties = properties + "\nChildNodes: " + checkBox.ChildNodes;
                    }

                    properties = properties + "\n";
                }
            }
            properties = properties + "\nTotal ActiveX Controls found: " + doc.GetChildNodes(NodeType.Shape, true).Count.ToString();
            Console.WriteLine("\n" + properties);
        }      
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:31,代码来源:ReadActiveXControlProperties.cs

示例3: Resample

        /// <summary>
        /// Resamples all images in the document that are greater than the specified PPI (pixels per inch) to the specified PPI
        /// and converts them to JPEG with the specified quality setting.
        /// </summary>
        /// <param name="doc">The document to process.</param>
        /// <param name="desiredPpi">Desired pixels per inch. 220 high quality. 150 screen quality. 96 email quality.</param>
        /// <param name="jpegQuality">0 - 100% JPEG quality.</param>
        /// <returns></returns>
        public static int Resample(Document doc, int desiredPpi, int jpegQuality)
        {
            int count = 0;

            // Convert VML shapes.
            foreach (Shape vmlShape in doc.GetChildNodes(NodeType.Shape, true, false))
            {
                // It is important to use this method to correctly get the picture shape size in points even if the picture is inside a group shape.
                SizeF shapeSizeInPoints = vmlShape.SizeInPoints;

                if (ResampleCore(vmlShape.ImageData, shapeSizeInPoints, desiredPpi, jpegQuality))
                    count++;
            }

            // Convert DrawingML shapes.
            foreach (DrawingML dmlShape in doc.GetChildNodes(NodeType.DrawingML, true, false))
            {
                // In MS Word the size of a DrawingML shape is always in points at the moment.
                SizeF shapeSizeInPoints = dmlShape.Size;
                if (ResampleCore(dmlShape.ImageData, shapeSizeInPoints, desiredPpi, jpegQuality))
                    count++;
            }

            return count;
        }
开发者ID:nausherwan-aslam,项目名称:Aspose_Words_NET,代码行数:33,代码来源:Resampler.cs

示例4: AddEx

        public void AddEx()
        {
            //ExStart
            //ExFor:TabStopCollection.Add(TabStop)
            //ExFor:TabStopCollection.Add(Double, TabAlignment, TabLeader)
            //ExSummary:Shows how to create tab stops and add them to a document.
            Document doc = new Document(MyDir + "Document.doc");
            Paragraph paragraph = (Paragraph)doc.GetChild(NodeType.Paragraph, 0, true);

            // Create a TabStop object and add it to the document.
            TabStop tabStop = new TabStop(ConvertUtil.InchToPoint(3), TabAlignment.Left, TabLeader.Dashes);
            paragraph.ParagraphFormat.TabStops.Add(tabStop);

            // Add a tab stop without explicitly creating new TabStop objects.
            paragraph.ParagraphFormat.TabStops.Add(ConvertUtil.MillimeterToPoint(100), TabAlignment.Left, TabLeader.Dashes);

            // Add tab stops at 5 cm to all paragraphs.
            foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
            {
                para.ParagraphFormat.TabStops.Add(ConvertUtil.MillimeterToPoint(50), TabAlignment.Left, TabLeader.Dashes);
            }

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

示例5: Run

        public static void Run()
        {
            // ExStart:InsertAuthorField
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithFields();
            Document doc = new Document(dataDir + "in.doc");
            // Get paragraph you want to append this AUTHOR field to
            Paragraph para = (Paragraph)doc.GetChildNodes(NodeType.Paragraph, true)[1];

            // We want to insert an AUTHOR field like this:
            // { AUTHOR Test1 }

            // Create instance of FieldAuthor class and lets build the above field code
            FieldAuthor field = (FieldAuthor)para.AppendField(FieldType.FieldAuthor, false);

            // { AUTHOR Test1 }
            field.AuthorName = "Test1";

            // Finally update this AUTHOR field
            field.Update();

            dataDir = dataDir + "InsertAuthorField_out.doc";
            doc.Save(dataDir);
            // ExEnd:InsertAuthorField
            Console.WriteLine("\nAuthor field without document builder inserted successfully.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:26,代码来源:InsertAuthorField.cs

示例6: Main

        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Aspose.Note.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            Dictionary<string, string> replacements = new Dictionary<string, string>();
            replacements.Add("Some task here", "New Text Here");

            // Load the document into Aspose.Note.
            Document oneFile = new Document(dataDir + "Aspose.one");

            IList<Node> pageNodes = oneFile.GetChildNodes(NodeType.Page);
            CompositeNode<Page> compositeNode = (CompositeNode<Page>)pageNodes[0];

            // Get all RichText nodes
            IList<Node> textNodes = compositeNode.GetChildNodes(NodeType.RichText);

            foreach (Node node in textNodes)
            {
                foreach (KeyValuePair<string, string> kvp in replacements)
                {
                    RichText richText = (RichText)node;
                    if (richText != null && richText.Text.Contains(kvp.Key))
                    {
                        // Replace text of a shape
                        richText.Text = richText.Text.Replace(kvp.Key, kvp.Value);
                    }
                }
            }

            // Save to any supported file format
            oneFile.Save(dataDir + "Output.pdf", SaveFormat.Pdf);
        }
开发者ID:saqibmasood,项目名称:Aspose_Note_NET,代码行数:33,代码来源:ReplaceTextOnParticularPage.cs

示例7: Run

        public static void Run()
        {
            // ExStart:KeepSourceTogether
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_JoiningAndAppending();
            string fileName = "TestFile.DestinationList.doc";

            Document dstDoc = new Document(dataDir + fileName);
            Document srcDoc = new Document(dataDir + "TestFile.Source.doc");

            // Set the source document to appear straight after the destination document's content.
            srcDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous;

            // Iterate through all sections in the source document.
            foreach (Paragraph para in srcDoc.GetChildNodes(NodeType.Paragraph, true))
            {
                para.ParagraphFormat.KeepWithNext = true;
            }

            dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            dstDoc.Save(dataDir);
            // ExEnd:KeepSourceTogether
            Console.WriteLine("\nDocument appended successfully while keeping the content from splitting across two pages.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:25,代码来源:KeepSourceTogether.cs

示例8: Main

        static void Main(string[] args)
        {
            // Check for license and apply if exists
            string licenseFile = AppDomain.CurrentDomain.BaseDirectory + "Aspose.Words.lic";
            if (File.Exists(licenseFile))
            {
                // Apply Aspose.Words API License
                Aspose.Words.License license = new Aspose.Words.License();
                // Place license file in Bin/Debug/ Folder
                license.SetLicense("Aspose.Words.lic");
            }

            string filePath = Path.GetDirectoryName(Path.GetDirectoryName(Directory.GetCurrentDirectory())) + @"\data\" + "Extract Images from Word Document.doc";

            Document wordDocument = new Document(filePath);
            
            NodeCollection pictures = wordDocument.GetChildNodes(NodeType.Shape, true);
            int imageindex = 0;
            foreach (Shape shape in pictures)
            {
                string imageType = FileFormatUtil.ImageTypeToExtension(shape.ImageData.ImageType);
                if (shape.HasImage)
                {
                    string imageFileName = "Aspose_" + (imageindex++).ToString() + "_" + shape.Name + imageType;
                    shape.ImageData.Save(imageFileName);
                }
            }

        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:29,代码来源:Program.cs

示例9: Run

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

            // Specify your document name here.
            Document doc = new Document(dataDir + "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";
                }
            }

            dataDir = dataDir + "RenameMergeFields_out.doc";
            doc.Save(dataDir);
            // ExEnd:RenameMergeFields
            Console.WriteLine("\nMerge fields rename successfully.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:25,代码来源:RenameMergeFields.cs

示例10: RemoveComments

 static void RemoveComments(Document doc)
 {
     // Collect all comments in the document
     NodeCollection comments = doc.GetChildNodes(NodeType.Comment, true);
     // Remove all comments.
     comments.Clear();
 }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:7,代码来源:ProcessComments.cs

示例11: 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.
            Document doc = new Document(MyDir + "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(MyDir + @"\Artifacts\Document.TableOfContentsTabStops.doc");
            //ExEnd
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:33,代码来源:ExStyles.cs

示例12: Run

        public static void Run()
        {
            
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithTables() + "Table.SimpleTable.doc";
            Document doc = new Document(dataDir);

            // ExStart:RetrieveTableIndex
            // Get the first table in the document.
            Table table = (Table)doc.GetChild(NodeType.Table, 0, true);

            NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
            int tableIndex = allTables.IndexOf(table);            
            // ExEnd:RetrieveTableIndex
            Console.WriteLine("\nTable index is " + tableIndex.ToString());

            // ExStart:RetrieveRowIndex
            int rowIndex = table.IndexOf((Row)table.LastRow);
            // ExEnd:RetrieveRowIndex
            Console.WriteLine("\nRow index is " + rowIndex.ToString());

            Row row = (Row)table.LastRow;
            // ExStart:RetrieveCellIndex
            int cellIndex = row.IndexOf(row.Cells[4]);
            // ExEnd:RetrieveCellIndex
            Console.WriteLine("\nCell index is " + cellIndex.ToString());
        
        }        
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:28,代码来源:FindingIndex.cs

示例13: Main

        static void Main(string[] args)
        {
            string FilePath = @"..\..\..\..\Sample Files\";
            string File = FilePath + "Extract Image - Aspose.docx";

            Document doc = new Document(File);

            // Save document as DOC in memory
            MemoryStream stream = new MemoryStream();
            doc.Save(stream, SaveFormat.Doc);

            // Reload document as DOC to extract images.
            Document doc2 = new Document(stream);
            NodeCollection shapes = doc2.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(FilePath + imageFileName);
                    imageIndex++;
                }
            }
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:26,代码来源:Program.cs

示例14: StretchImage_fitSize

        public void StretchImage_fitSize()
        {
            Document doc = DocumentHelper.CreateTemplateDocumentForReportingEngine("<<image [src.Image] -fitSize>>");

            ImageStream imageStream = new ImageStream(new FileStream(_image, FileMode.Open, FileAccess.Read));

            BuildReport(doc, imageStream, "src");

            MemoryStream dstStream = new MemoryStream();
            doc.Save(dstStream, SaveFormat.Docx);

            doc = new Document(dstStream);

            NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

            foreach (Shape shape in shapes)
            {
                // Assert that the image is really insert in textbox
                Assert.IsTrue(shape.ImageData.HasImage);

                //Assert that height is changed and width is changed
                Assert.AreNotEqual(346.35, shape.Height);
                Assert.AreNotEqual(431.5, shape.Width);
            }

            dstStream.Dispose();
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:27,代码来源:QaEngine.cs

示例15: Run

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

            string fileName = "Document.TableOfContents.doc";
            // Open the document.
            Document doc = new Document(dataDir + fileName);
        
            // 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);
                }
            }

            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            doc.Save(dataDir);            
            // ExEnd:ChangeTOCTabStops 
            Console.WriteLine("\nPosition of the right tab stop in TOC related paragraphs modified successfully.\nFile saved at " + dataDir);
        }        
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:31,代码来源:ChangeTOCTabStops.cs


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