Merge remote-tracking branch 'origin/dev' into masse_salariale_jp
authorJean-Philippe Caissy <jpcaissy@piji.ca>
Wed, 28 Mar 2012 13:26:03 +0000 (08:26 -0500)
committerJean-Philippe Caissy <jpcaissy@piji.ca>
Wed, 28 Mar 2012 13:26:03 +0000 (08:26 -0500)
project/rh/masse_salariale.py
project/rh/ods.py

index 46223be..4d7decd 100644 (file)
@@ -527,6 +527,7 @@ class MasseSalariale():
             if len(h) > 2:
                 table.add_column(**h[2])
 
-        table.add_row([h[1] for h in self.headers], rowheight='2cm', verticalalign='middle')
-
+        table.add_row([h[1] for h in self.headers], rowheight='2cm',
+                fontweight='bold')
 
+        #a.doc.write('hello_world.ods')
index eb84a37..cbe2fce 100644 (file)
@@ -5,6 +5,10 @@ from decimal import Decimal
 import odf.opendocument
 import odf.style
 import odf.table
+from odf.style import Style, MasterPage, PageLayout, PageLayoutProperties, \
+        TextProperties, GraphicProperties, ParagraphProperties, DrawingPageProperties
+from odf.text import P
+
 
 
 class Wrapper(object):
@@ -44,28 +48,27 @@ class Table(Wrapper):
 
     def add_row(self, values=[], **kwargs):
          # attributs appartenant à table-column-poperties
-        props = {}
-        for attr in ['rowheight']:
-            if attr in kwargs:
-                props[attr] = kwargs.pop(attr)
+#        props = {}
+#        for attr in ['rowheight']:
+#            if attr in kwargs:
+#                props[attr] = kwargs.pop(attr)
 
-        style = self._doc.add_automatic_style()
+        style = self._doc.add_automatic_style(family='table-row')
         if 'rowheight' in kwargs:
             style.addElement(odf.style.TableRowProperties(
                 rowheight=kwargs['rowheight']))
             kwargs['stylename'] = style.getAttribute('name')
             del kwargs['rowheight']
 
-        if 'verticalalign' in kwargs:
-            style.addElement(odf.style.TableCellProperties(
-                verticalalign=kwargs['verticalalign']))
-            kwargs['stylename'] = style.getAttribute('name')
-            del kwargs['verticalalign']
-
+        style = {}
+        if 'fontweight' in kwargs:
+            style['fontweight'] = kwargs['fontweight']
+            del kwargs['fontweight']
 
         row = TableRow(**kwargs)
+        row._doc = self._doc
         for value in values:
-            row.add_cell(value)
+            row.add_cell(value, verticalalign='middle', **style)
         self.addElement(row)
         return row
 
@@ -96,6 +99,29 @@ class TableRow(Wrapper):
             elif isinstance(value, (int, float, Decimal)):
                 kwargs['valuetype'] = 'float'
                 kwargs['value'] = float(value)
+
+        if 'verticalalign' in kwargs:
+            style = self._doc.add_automatic_style(family='table-cell')
+            style.addElement(odf.style.TableCellProperties(
+                verticalalign=kwargs['verticalalign']))
+            kwargs['stylename'] = style.getAttribute('name')
+            del kwargs['verticalalign']
+
+        props = {}
+        if 'fontweight' in kwargs:
+            props['fontweight'] = kwargs.pop('fontweight')
+        if 'stringvalue' in kwargs:
+            props['stringvalue'] = kwargs.pop('stringvalue')
+
         cell = odf.table.TableCell(**kwargs)
+        if 'fontweight' in props:
+            tablecontents = Style(name="Bold", family="paragraph")
+            tablecontents.addElement(TextProperties(fontweight="bold"))
+            self._doc.styles.addElement(tablecontents)
+
+        if 'stringvalue' in props:
+            p = P(stylename='Bold',text=props['stringvalue'])
+            cell.addElement(p)
+
         self.addElement(cell)
         return cell