static CellFormatPart() { NAMED_COLORS = new Dictionary <String, Color>(CASE_INSENSITIVE_ORDER); Hashtable colors = HSSFColor.GetIndexHash(); foreach (object v in colors.Values) { HSSFColor hc = (HSSFColor)v; Type type = hc.GetType(); String name = type.Name; if (name.Equals(name.ToUpper())) { short[] rgb = hc.GetTriplet(); Color c = Color.FromArgb(rgb[0], rgb[1], rgb[2]); if (!NAMED_COLORS.ContainsKey(name)) { NAMED_COLORS.Add(name, c); } if (name.IndexOf('_') > 0) { if (!NAMED_COLORS.ContainsKey(name.Replace('_', ' '))) { NAMED_COLORS.Add(name.Replace('_', ' '), c); } } if (name.IndexOf("_PERCENT") > 0) { if (!NAMED_COLORS.ContainsKey(name.Replace("_PERCENT", "%").Replace('_', ' '))) { NAMED_COLORS.Add(name.Replace("_PERCENT", "%").Replace('_', ' '), c); } } } } // A condition specification String condition = "([<>=]=?|!=|<>) # The operator\n" + " \\s*([0-9]+(?:\\.[0-9]*)?)\\s* # The constant to test against\n"; String color = "\\[(black|blue|cyan|green|magenta|red|white|yellow|color [0-9]+)\\]"; // A number specification // Note: careful that in something like ##, that the trailing comma is not caught up in the integer part // A part of a specification String part = "\\\\. # Quoted single character\n" + "|\"([^\\\\\"]|\\\\.)*\" # Quoted string of characters (handles escaped quotes like \\\") \n" + "|_. # Space as wide as a given character\n" + "|\\*. # Repeating fill character\n" + "|@ # Text: cell text\n" + "|([0?\\#](?:[0?\\#,]*)) # Number: digit + other digits and commas\n" + "|e[-+] # Number: Scientific: Exponent\n" + "|m{1,5} # Date: month or minute spec\n" + "|d{1,4} # Date: day/date spec\n" + "|y{2,4} # Date: year spec\n" + "|h{1,2} # Date: hour spec\n" + "|s{1,2} # Date: second spec\n" + "|am?/pm? # Date: am/pm spec\n" + "|\\[h{1,2}\\] # Elapsed time: hour spec\n" + "|\\[m{1,2}\\] # Elapsed time: minute spec\n" + "|\\[s{1,2}\\] # Elapsed time: second spec\n" + "|[^;] # A character\n" + ""; String format = "(?:" + color + ")? # Text color\n" + "(?:\\[" + condition + "\\])? # Condition\n" + "((?:" + part + ")+) # Format spec\n"; RegexOptions flags = RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled; COLOR_PAT = new Regex(color, flags); CONDITION_PAT = new Regex(condition, flags); SPECIFICATION_PAT = new Regex(part, flags); FORMAT_PAT = new Regex(format, flags); // Calculate the group numbers of important groups. (They shift around // when the pattern is Changed; this way we figure out the numbers by // experimentation.) COLOR_GROUP = FindGroup(FORMAT_PAT, "[Blue]@", "Blue"); CONDITION_OPERATOR_GROUP = FindGroup(FORMAT_PAT, "[>=1]@", ">="); CONDITION_VALUE_GROUP = FindGroup(FORMAT_PAT, "[>=1]@", "1"); SPECIFICATION_GROUP = FindGroup(FORMAT_PAT, "[Blue][>1]\\a ?", "\\a ?"); }