ExtractContent() public static method

public static ExtractContent ( Node startNode, Node endNode, bool isInclusive ) : ArrayList
startNode Node
endNode Node
isInclusive bool
return System.Collections.ArrayList
コード例 #1
0
        public static void Run()
        {
            //ExStart:ExtractContentUsingField
            // The path to the documents directory.
            string   dataDir  = RunExamples.GetDataDir_WorkingWithDocument();
            string   fileName = "TestFile.doc";
            Document doc      = new Document(dataDir + fileName);

            // Use a document builder to retrieve the field start of a merge field.
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Pass the first boolean parameter to get the DocumentBuilder to move to the FieldStart of the field.
            // We could also get FieldStarts of a field using GetChildNode method as in the other examples.
            builder.MoveToMergeField("Fullname", false, false);

            // The builder cursor should be positioned at the start of the field.
            FieldStart startField = (FieldStart)builder.CurrentNode;
            Paragraph  endPara    = (Paragraph)doc.FirstSection.GetChild(NodeType.Paragraph, 5, true);

            // Extract the content between these nodes in the document. Don't include these markers in the extraction.
            ArrayList extractedNodes = Common.ExtractContent(startField, endPara, false);

            // Insert the content into a new separate document and save it to disk.
            Document dstDoc = Common.GenerateDocument(doc, extractedNodes);

            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            dstDoc.Save(dataDir);
            //ExEnd:ExtractContentUsingField
            Console.WriteLine("\nExtracted content using the Field successfully.\nFile saved at " + dataDir);
        }
        public static void Run()
        {
            // ExStart:ExtractContentBetweenParagraphStyles
            // The path to the documents directory.
            string   dataDir  = RunExamples.GetDataDir_WorkingWithDocument();
            string   fileName = "TestFile.doc";
            Document doc      = new Document(dataDir + fileName);

            // Gather a list of the paragraphs using the respective heading styles.
            ArrayList parasStyleHeading1 = Common.ParagraphsByStyleName(doc, "Heading 1");
            ArrayList parasStyleHeading3 = Common.ParagraphsByStyleName(doc, "Heading 3");

            // Use the first instance of the paragraphs with those styles.
            Node startPara1 = (Node)parasStyleHeading1[0];
            Node endPara1   = (Node)parasStyleHeading3[0];

            // Extract the content between these nodes in the document. Don't include these markers in the extraction.
            ArrayList extractedNodes = Common.ExtractContent(startPara1, endPara1, false);

            // Insert the content into a new separate document and save it to disk.
            Document dstDoc = Common.GenerateDocument(doc, extractedNodes);

            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            dstDoc.Save(dataDir);
            // ExEnd:ExtractContentBetweenParagraphStyles
            Console.WriteLine("\nExtracted content betweenn the paragraph styles successfully.\nFile saved at " + dataDir);
        }
コード例 #3
0
        public static void Run()
        {
            // ExStart:ExtractContentBetweenRuns
            // The path to the documents directory.
            string   dataDir  = RunExamples.GetDataDir_WorkingWithDocument();
            string   fileName = "TestFile.doc";
            Document doc      = new Document(dataDir + fileName);

            // Retrieve a paragraph from the first section.
            Paragraph para = (Paragraph)doc.GetChild(NodeType.Paragraph, 7, true);

            // Use some runs for extraction.
            Run startRun = para.Runs[1];
            Run endRun   = para.Runs[4];

            // Extract the content between these nodes in the document. Include these markers in the extraction.
            ArrayList extractedNodes = Common.ExtractContent(startRun, endRun, true);

            // Get the node from the list. There should only be one paragraph returned in the list.
            Node node = (Node)extractedNodes[0];

            // Print the text of this node to the console.
            Console.WriteLine(node.ToString(SaveFormat.Text));
            // ExEnd:ExtractContentBetweenRuns
            Console.WriteLine("\nExtracted content betweenn the runs successfully.");
        }
コード例 #4
0
        public static void Run()
        {
            //ExStart:ExtractContentBetweenBookmark
            // The path to the documents directory.
            string   dataDir  = RunExamples.GetDataDir_WorkingWithDocument();
            string   fileName = "TestFile.doc";
            Document doc      = new Document(dataDir + fileName);

            Section section = doc.Sections[0];

            section.PageSetup.LeftMargin = 70.85;

            // Retrieve the bookmark from the document.
            Bookmark bookmark = doc.Range.Bookmarks["Bookmark1"];

            // We use the BookmarkStart and BookmarkEnd nodes as markers.
            BookmarkStart bookmarkStart = bookmark.BookmarkStart;
            BookmarkEnd   bookmarkEnd   = bookmark.BookmarkEnd;

            // Firstly extract the content between these nodes including the bookmark.
            ArrayList extractedNodesInclusive = Common.ExtractContent(bookmarkStart, bookmarkEnd, true);
            Document  dstDoc = Common.GenerateDocument(doc, extractedNodesInclusive);

            dstDoc.Save(dataDir + "TestFile.BookmarkInclusive_out_.doc");

            // Secondly extract the content between these nodes this time without including the bookmark.
            ArrayList extractedNodesExclusive = Common.ExtractContent(bookmarkStart, bookmarkEnd, false);

            dstDoc = Common.GenerateDocument(doc, extractedNodesExclusive);
            dstDoc.Save(dataDir + "TestFile.BookmarkExclusive_out_.doc");
            //ExEnd:ExtractContentBetweenBookmark
            Console.WriteLine("\nExtracted content between bookmarks successfully.\nFile saved at " + dataDir + "TestFile.BookmarkExclusive_out_.doc");
        }
        public static void Run()
        {
            //ExStart:ExtractContentBetweenCommentRange
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithDocument();

            Document doc = new Document(dataDir + "TestFile.doc");

            // This is a quick way of getting both comment nodes.
            // Your code should have a proper method of retrieving each corresponding start and end node.
            CommentRangeStart commentStart = (CommentRangeStart)doc.GetChild(NodeType.CommentRangeStart, 0, true);
            CommentRangeEnd   commentEnd   = (CommentRangeEnd)doc.GetChild(NodeType.CommentRangeEnd, 0, true);

            // Firstly extract the content between these nodes including the comment as well.
            ArrayList extractedNodesInclusive = Common.ExtractContent(commentStart, commentEnd, true);
            Document  dstDoc = Common.GenerateDocument(doc, extractedNodesInclusive);

            dstDoc.Save(dataDir + "TestFile.CommentInclusive_out_.doc");

            // Secondly extract the content between these nodes without the comment.
            ArrayList extractedNodesExclusive = Common.ExtractContent(commentStart, commentEnd, false);

            dstDoc = Common.GenerateDocument(doc, extractedNodesExclusive);
            dstDoc.Save(dataDir + "TestFile.CommentExclusive_out_.doc");
            //ExEnd:ExtractContentBetweenCommentRange
            Console.WriteLine("\nExtracted content between the comment range successfully.\nFile saved at " + dataDir + "TestFile.CommentExclusive_out_.doc");
        }
        public static void Run()
        {
            // ExStart:ExtractContentBetweenBlockLevelNodes
            // The path to the documents directory.
            string   dataDir  = RunExamples.GetDataDir_WorkingWithDocument();
            string   fileName = "TestFile.doc";
            Document doc      = new Document(dataDir + fileName);

            Paragraph startPara = (Paragraph)doc.LastSection.GetChild(NodeType.Paragraph, 2, true);
            Table     endTable  = (Table)doc.LastSection.GetChild(NodeType.Table, 0, true);

            // Extract the content between these nodes in the document. Include these markers in the extraction.
            ArrayList extractedNodes = Common.ExtractContent(startPara, endTable, true);

            // Lets reverse the array to make inserting the content back into the document easier.
            extractedNodes.Reverse();

            while (extractedNodes.Count > 0)
            {
                // Insert the last node from the reversed list
                endTable.ParentNode.InsertAfter((Node)extractedNodes[0], endTable);
                // Remove this node from the list after insertion.
                extractedNodes.RemoveAt(0);
            }
            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            // Save the generated document to disk.
            doc.Save(dataDir);
            // ExEnd:ExtractContentBetweenBlockLevelNodes
            Console.WriteLine("\nExtracted content betweenn the block level nodes successfully.\nFile saved at " + dataDir);
        }
コード例 #7
0
        public static void Run()
        {
            //ExStart:ExtractContentBetweenParagraphs
            // The path to the documents directory.
            string   dataDir  = RunExamples.GetDataDir_WorkingWithDocument();
            string   fileName = "TestFile.doc";
            Document doc      = new Document(dataDir + fileName);

            // Gather the nodes. The GetChild method uses 0-based index
            Paragraph startPara = (Paragraph)doc.FirstSection.GetChild(NodeType.Paragraph, 6, true);
            Paragraph endPara   = (Paragraph)doc.FirstSection.GetChild(NodeType.Paragraph, 10, true);
            // Extract the content between these nodes in the document. Include these markers in the extraction.
            ArrayList extractedNodes = Common.ExtractContent(startPara, endPara, true);

            // Insert the content into a new separate document and save it to disk.
            Document dstDoc = Common.GenerateDocument(doc, extractedNodes);

            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            dstDoc.Save(dataDir);
            //ExEnd:ExtractContentBetweenParagraphs
            Console.WriteLine("\nExtracted content betweenn the paragraphs successfully.\nFile saved at " + dataDir);
        }