GetParagraph() статический приватный Метод

Get paragraph of the current document
static private GetParagraph ( Document doc, int paraIndex ) : Paragraph
doc Document /// Current document ///
paraIndex int /// Paragraph number from collection ///
Результат Paragraph
        /// <summary>
        /// Insert field into the first paragraph of the current document using field code and field String.
        /// </summary>
        private static void InsertFieldUsingFieldCodeFieldString(Document doc, string fieldCode, string fieldValue,
                                                                 Node refNode, bool isAfter, int paraIndex)
        {
            Paragraph para = DocumentHelper.GetParagraph(doc, paraIndex);

            para.InsertField(fieldCode, fieldValue, refNode, isAfter);
        }
        /// <summary>
        /// Insert field into the first paragraph of the current document using field type.
        /// </summary>
        private static void InsertFieldUsingFieldType(Document doc, FieldType fieldType, bool updateField, Node refNode,
                                                      bool isAfter, int paraIndex)
        {
            Paragraph para = DocumentHelper.GetParagraph(doc, paraIndex);

            para.InsertField(fieldType, updateField, refNode, isAfter);
        }
        public void GetFormatRevision()
        {
            //ExStart
            //ExFor:Paragraph.IsFormatRevision
            //ExSummary:Shows how to get information about whether this object was formatted in Microsoft Word while change tracking was enabled
            Document doc = new Document(MyDir + "Paragraph.IsFormatRevision.docx");

            Paragraph firstParagraph = DocumentHelper.GetParagraph(doc, 0);

            Assert.IsTrue(firstParagraph.IsFormatRevision);
            //ExEnd

            Paragraph secondParagraph = DocumentHelper.GetParagraph(doc, 1);

            Assert.IsFalse(secondParagraph.IsFormatRevision);
        }
        public void GetFrameProperties()
        {
            Document doc = new Document(MyDir + "Paragraph.Frame.docx");

            Paragraph frame = DocumentHelper.GetParagraph(doc, 0);

            Assert.True(frame.FrameFormat.IsFrame);

            Assert.AreEqual(233.3, frame.FrameFormat.Width);
            Assert.AreEqual(138.8, frame.FrameFormat.Height);
            Assert.AreEqual(21.05, frame.FrameFormat.HorizontalPosition);
            Assert.AreEqual(RelativeHorizontalPosition.Page, frame.FrameFormat.RelativeHorizontalPosition);
            Assert.AreEqual(9, frame.FrameFormat.HorizontalDistanceFromText);
            Assert.AreEqual(-17.65, frame.FrameFormat.VerticalPosition);
            Assert.AreEqual(RelativeVerticalPosition.Paragraph, frame.FrameFormat.RelativeVerticalPosition);
            Assert.AreEqual(0, frame.FrameFormat.VerticalDistanceFromText);
        }
Пример #5
0
        public void UpdatePageNumbersInToc()
        {
            Document doc = new Document(MyDir + "Field.UpdateTocPages.docx");

            Node startNode = DocumentHelper.GetParagraph(doc, 2);
            Node endNode   = null;

            NodeCollection paragraphCollection = doc.GetChildNodes(NodeType.Paragraph, true);

            foreach (Paragraph para in paragraphCollection.OfType <Paragraph>())
            {
                // Check all runs in the paragraph for the first page breaks.
                foreach (Run run in para.Runs.OfType <Run>())
                {
                    if (run.Text.Contains(ControlChar.PageBreak))
                    {
                        endNode = run;
                        break;
                    }
                }
            }

            if (startNode != null && endNode != null)
            {
                RemoveSequence(startNode, endNode);

                startNode.Remove();
                endNode.Remove();
            }

            NodeCollection fStart = doc.GetChildNodes(NodeType.FieldStart, true);

            foreach (FieldStart field in fStart.OfType <FieldStart>())
            {
                FieldType fType = field.FieldType;
                if (fType == FieldType.FieldTOC)
                {
                    Paragraph para = (Paragraph)field.GetAncestor(NodeType.Paragraph);
                    para.Range.UpdateFields();
                    break;
                }
            }

            doc.Save(MyDir + @"\Artifacts\Field.UpdateTocPages.docx");
        }