Commits

Eric Gazoni committed 58d23c9

[styles] fix an issue with fill not being written

  • Participants
  • Parent commits 804e62a
  • Branches 1.9

Comments (0)

Files changed (3)

File openpyxl/styles/fills.py

 
 from .colors import Color
 from .hashable import HashableObject
+import warnings
 
 
 class Fill(HashableObject):
-    """Area fill patterns for use in styles."""
+    """Area fill patterns for use in styles.
+    Caution: if you do not specify a fill_type, other attributes will have
+    no effect !"""
     FILL_NONE = None
     FILL_SOLID = 'solid'
     FILL_GRADIENT_LINEAR = 'linear'

File openpyxl/tests/test_style.py

 
     ws.column_dimensions['A'].width = 20
     i_style = ws.get_style('I')
-    print "***", i_style.fill
-    ws.set_style('I', i_style.copy(fill=Fill(start_color=Color('FF442200')),
+    ws.set_style('I', i_style.copy(fill=Fill(fill_type='solid',
+                                             start_color=Color('FF442200')),
                                    font=Font(color=Color('FF002244'))))
     ws.cell('A2').style = ws.cell('A2').style.copy(font=Font(name='Times New Roman',
                                                              size=12,
                                                              italic=False))
     ws.cell('A5').style = ws.cell('A5').style.copy(font=Font(color=Color('FF66FF66')))
     ws.cell('A6').style = ws.cell('A6').style.copy(font=Font(color=Color('theme:1:')))
-    ws.cell('A7').style = ws.cell('A7').style.copy(fill=Fill(start_color=Color('FF330066')))
-    ws.cell('A8').style = ws.cell('A8').style.copy(fill=Fill(start_color=Color('theme:2:')))
+    ws.cell('A7').style = ws.cell('A7').style.copy(fill=Fill(fill_type='solid',
+                                                             start_color=Color('FF330066')))
+    ws.cell('A8').style = ws.cell('A8').style.copy(fill=Fill(fill_type='solid',
+                                                             start_color=Color('theme:2:')))
     ws.cell('A9').style = ws.cell('A9').style.copy(alignment=Alignment(horizontal='center'))
     ws.cell('A10').style = ws.cell('A10').style.copy(alignment=Alignment(horizontal='left'))
     ws.cell('A11').style = ws.cell('A11').style.copy(alignment=Alignment(horizontal='right'))

File openpyxl/writer/styles.py

         """
         if color is None:
             return
-        print color, node
         if not ":" in color:
             SubElement(node, key, {'rgb': color})
         else:
         index = 2
         for st in self._style_list:
             if st.fill != DEFAULTS.fill and st.fill not in table:
-                print st.fill
                 table[st.fill] = index
                 fill = SubElement(fills, 'fill')
-                if st.fill != DEFAULTS.fill:
-                    node = SubElement(fill, 'patternFill', {'patternType':st.fill.fill_type})
+                if st.fill != DEFAULTS.fill and st.fill.fill_type is not None:
+                    node = SubElement(fill, 'patternFill', {'patternType': st.fill.fill_type})
                     if st.fill.start_color != DEFAULTS.fill.start_color:
                         self._unpack_color(node, st.fill.start_color.index, 'fgColor')
                     if st.fill.end_color != DEFAULTS.fill.end_color: