Example #1
0
        internal static string GetFieldNameWithOptions(SimpleField field, out string[] switches, out string[] options)
        {
            OpenXmlAttribute attribute = field.GetAttribute("instr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");

            switches = new string[0];
            options  = new string[3];
            string str   = string.Empty;
            string input = attribute.Value;

            if (!string.IsNullOrEmpty(input))
            {
                Match match = DocumentMerge.instructionRegEx.Match(input);
                if (match.Success)
                {
                    str        = match.Groups["name"].ToString().Trim();
                    options[0] = match.Groups["Format"].Value.Trim();
                    options[1] = match.Groups["PreText"].Value.Trim();
                    options[2] = match.Groups["PostText"].Value.Trim();
                    int length = str.IndexOf('#');
                    if (length > 0)
                    {
                        switches = str.Substring(length + 1).ToLower().Split(new char[1]
                        {
                            '#'
                        }, StringSplitOptions.RemoveEmptyEntries);
                        str = str.Substring(0, length);
                    }
                }
            }
            return(str);
        }
Example #2
0
        /// <summary>
        /// Returns the fieldname and switches from the given mergefield-instruction
        /// Note: the switches are always returned lowercase !
        /// Note 2: options holds values for formatting and text to insert before and/or after the field value.
        ///         options[0] = Formatting (Upper, Lower, Caps a.k.a. title case, FirstCap)
        ///         options[1] = Text to insert before data
        ///         options[2] = Text to insert after data
        /// </summary>
        /// <param name="field">The field being examined.</param>
        /// <param name="switches">An array of switches to apply to the field.</param>
        /// <param name="options">Formatting options to apply.</param>
        /// <returns>The name of the field.</returns>
        private static string GetFieldNameWithOptions(SimpleField field, out string[] switches, out string[] options)
        {
            var attribute = field.GetAttribute("instr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");

            switches = new string[0];
            options  = new string[3];
            string fieldName   = string.Empty;
            string instruction = attribute.Value;

            if (!string.IsNullOrEmpty(instruction))
            {
                var match = rgxInstruction.Match(instruction);
                if (match.Success)
                {
                    fieldName  = match.Groups["name"].ToString().Trim();
                    options[0] = match.Groups["Format"].Value.Trim();
                    options[1] = match.Groups["PreText"].Value.Trim();
                    options[2] = match.Groups["PostText"].Value.Trim();
                    int pos = fieldName.IndexOf('#');
                    if (pos > 0)
                    {
                        // Process the switches, correct the fieldname.
                        switches  = fieldName.Substring(pos + 1).ToLower().Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                        fieldName = fieldName.Substring(0, pos);
                    }
                }
            }

            return(fieldName);
        }
Example #3
0
        /// <summary>
        /// Returns the fieldname and switches from the given mergefield-instruction
        /// Note: the switches are always returned lowercase !
        /// Note 2: options holds values for formatting and text to insert before and/or after the field value.
        ///         options[0] = Formatting (Upper, Lower, Caps a.k.a. title case, FirstCap)
        ///         options[1] = Text to insert before data
        ///         options[2] = Text to insert after data
        /// </summary>
        /// <param name="field">The field being examined.</param>
        /// <param name="switches">An array of switches to apply to the field.</param>
        /// <param name="options">Formatting options to apply.</param>
        /// <returns>The name of the field.</returns>
        private string GetFieldNameWithOptions(SimpleField field, out string[] switches, out string[] options)
        {
            var a = field.GetAttribute("instr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");

            switches = new string[0];
            options  = new string[3];
            string fieldname   = string.Empty;
            string instruction = a.Value;

            if (!string.IsNullOrEmpty(instruction))
            {
                Match m = this.instructionRegEx.Match(instruction);
                if (m.Success)
                {
                    fieldname  = m.Groups["name"].ToString().Trim();
                    options[0] = m.Groups["Format"].Value.Trim();
                    options[1] = m.Groups["PreText"].Value.Trim();
                    options[2] = m.Groups["PostText"].Value.Trim();
                    int pos = fieldname.IndexOf('#');
                    if (pos > 0)
                    {
                        // Process the switches, correct the fieldname.
                        // ReSharper disable RedundantExplicitArrayCreation
                        switches = fieldname.Substring(pos + 1).ToLower().Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                        // ReSharper restore RedundantExplicitArrayCreation
                        fieldname = fieldname.Substring(0, pos);
                    }
                }
            }

            return(fieldname);
        }
        /// <summary>
        /// Returns the fieldname and switches from the given mergefield-instruction
        /// Note: the switches are always returned lowercase !
        /// </summary>
        /// <param name="field">The field being examined.</param>
        /// <param name="switches">An array of switches to apply to the field.</param>
        /// <returns>The name of the field.</returns>
        internal static string GetFieldName(SimpleField field, out string[] switches)
        {
            var a = field.GetAttribute("instr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");

            switches = new string[0];
            string fieldname   = string.Empty;
            string instruction = a.Value;

            if (!string.IsNullOrEmpty(instruction))
            {
                Match m = instructionRegEx.Match(instruction);
                if (m.Success)
                {
                    fieldname = m.Groups["name"].ToString().Trim();
                    int pos = fieldname.IndexOf('#');
                    if (pos > 0)
                    {
                        // Process the switches, correct the fieldname.
                        switches  = fieldname.Substring(pos + 1).ToLower().Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                        fieldname = fieldname.Substring(0, pos);
                    }
                }
            }

            return(fieldname);
        }
Example #5
0
        /// <summary>
        /// Returns the fieldname and switches from the given mergefield-instruction
        /// Note: the switches are always returned lowercase !
        /// Note 2: options holds values for formatting and text to insert before and/or after the field value.
        ///         options[0] = Formatting (Upper, Lower, Caps a.k.a. title case, FirstCap)
        ///         options[1] = Text to insert before data
        ///         options[2] = Text to insert after data
        /// </summary>
        /// <param name="field">The field being examined.</param>
        /// <param name="switches">An array of switches to apply to the field.</param>
        /// <param name="options">Formatting options to apply.</param>
        /// <returns>The name of the field.</returns>
        static string GetFieldNameWithOptions(SimpleField field, out string[] switches, out string[] options)
        {
            var a = field.GetAttribute("instr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");

            switches = new string[0];
            options  = new string[3];
            string fieldname   = string.Empty;
            string instruction = a.Value;

            if (!string.IsNullOrEmpty(instruction))
            {
                Match m = instructionRegEx.Match(instruction);
                if (m.Success)
                {
                    fieldname  = m.Groups["name"].ToString().Trim();
                    options[0] = m.Groups["Format"].Value.Trim();
                    options[1] = m.Groups["PreText"].Value.Trim(); //becuase fixed we remove double quetes l.g
                    options[2] = m.Groups["PostText"].Value;       //.Trim();1.0.0.8.3
                    int pos = fieldname.IndexOf('#');
                    if (!String.IsNullOrEmpty(options[1]))
                    {
                        var removeDoubleQuotesExpr = @"[^\\""]*(\\""[^\\""]*)*";
                        var removeDoubleQuotes     = new Regex(removeDoubleQuotesExpr);

                        Match matchSyntax = removeDoubleQuotes.Match(options[1]);

                        if (matchSyntax.Success)
                        {
                            options[1] = matchSyntax.Groups[0] != null && String.IsNullOrEmpty(matchSyntax.Groups[0].Value) ? options[1] : matchSyntax.Groups[0].Value;
                        }
                    }
                    //start 1.0.0.8.3
                    if (!String.IsNullOrEmpty(options[2]))
                    {
                        var removeDoubleQuotesExpr = @"[^\\""]*(\\""[^\\""]*)*";
                        var removeDoubleQuotes     = new Regex(removeDoubleQuotesExpr);

                        Match matchSyntax = removeDoubleQuotes.Match(options[2]);

                        if (matchSyntax.Success)
                        {
                            options[2] = matchSyntax.Groups[0] != null && String.IsNullOrEmpty(matchSyntax.Groups[0].Value) ? options[2] : matchSyntax.Groups[0].Value;
                        }
                    }
                    //end 1.0.0.8.3
                    if (pos > 0)
                    {
                        // Process the switches, correct the fieldname.
                        switches  = fieldname.Substring(pos + 1).ToLower().Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                        fieldname = fieldname.Substring(0, pos);
                    }
                }
            }

            return(fieldname);
        }
        internal static string GetFieldName(SimpleField pField)
        {
            var attr = pField.GetAttribute("instr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            string strFieldname = string.Empty;
            string instruction = attr.Value;

            if (!string.IsNullOrEmpty(instruction))
            {
                Match m = instructionRegEx.Match(instruction);
                if (m.Success)
                {
                    strFieldname = m.Groups["name"].ToString().Trim();
                }
            }

            return strFieldname;
        }