Commits

Charlie Clark  committed 50f03e2

Initial refactoring of conditional formatting - delegate parsing intelligence to objects.

  • Participants
  • Parent commits 6277c61
  • Branches CF improvements

Comments (0)

Files changed (2)

File openpyxl/formatting/rules.py

 
 from collections import Mapping
 
+from openpyxl.compat import iteritems
 from openpyxl.styles import Font, Fill, Borders
 
 
 
     __slots__ = ('aboveAverage', 'bottom', 'dxfId', 'equalAverage',
                  'operator', 'percent', 'priority', 'rank', 'stdDev', 'stopIfTrue',
-                 'text', 'type')
+                 'text', 'type', 'formula', 'colorScale', 'iconSet')
 
     def update(self, dictionary):
         for k, v in iteritems(dictionary):
         return r
 
 
+class IconSetRule(object):
+
+    pass

File openpyxl/reader/worksheet.py

 from openpyxl.xml.constants import SHEET_MAIN_NS
 from openpyxl.xml.functions import safe_iterator
 from openpyxl.styles import Color
-from openpyxl.styles.formatting import ConditionalFormatting
+from openpyxl.formatting import ConditionalFormatting
+from openpyxl.formatting.rules import FormatRule, CellIsRule, ColorScaleRule, FormatRule
 
 
 def _get_xml_iter(xml_source):
             if range_string not in self.ws.conditional_formatting.parse_rules:
                 self.ws.conditional_formatting.parse_rules[range_string] = []
             for cfRule in cfRules:
-                if not cfRule.get('type') or cfRule.get('type') == 'dataBar':
+                rule_type = cfRule.get('type')
+                if rule_type in (None, 'dataBar'):
                     # dataBar conditional formatting isn't supported, as it relies on the complex <extLst> tag
                     continue
                 rule = {'type': cfRule.get('type')}
-                for attr in ConditionalFormatting.rule_attributes:
-                    if cfRule.get(attr) is not None:
-                        if attr == 'priority':
-                            rule[attr] = int(cfRule.get(attr))
-                        else:
-                            rule[attr] = cfRule.get(attr)
+                rule = FormatRule()
 
                 formula = cfRule.findall('{%s}formula' % SHEET_MAIN_NS)
                 for f in formula: