docs: def table(contents, heading=True, colw=None, cwunit='dxa', tblw=0,
            twunit='auto', borders={}, celstyle=None):
      """
      Return a table element based on specified parameters
  
      @param list contents: A list of lists describing contents. Every item in
                            the list can be a string or a valid XML element
                            itself. It can also be a list. In that case all the
                            listed elements will be merged into the cell.
      @param bool heading:  Tells whether first line should be treated as
                            heading or not
      @param list colw:     list of integer column widths specified in wunitS.
      @param str  cwunit:   Unit used for column width:
                              'pct'  : fiftieths of a percent
                              'dxa'  : twentieths of a point
                              'nil'  : no width
                              'auto' : automagically determined
      @param int  tblw:     Table width
      @param str  twunit:   Unit used for table width. Same possible values as
                            cwunit.
      @param dict borders:  Dictionary defining table border. Supported keys
                            are: 'top', 'left', 'bottom', 'right',
                            'insideH', 'insideV', 'all'.
                            When specified, the 'all' key has precedence over
                            others. Each key must define a dict of border
                            attributes:
                              color : The color of the border, in hex or
                                      'auto'
                              space : The space, measured in points
                              sz    : The size of the border, in eighths of
                                      a point
                              val   : The style of the border, see
                  http://www.schemacentral.com/sc/ooxml/t-w_ST_Border.htm
      @param list celstyle: Specify the style for each colum, list of dicts.
                            supported keys:
                            'align' : specify the alignment, see paragraph
                                      documentation.
      @return lxml.etree:   Generated XML etree element
      """
      table = makeelement('tbl')
      columns = len(contents[0])
      # Table properties
      tableprops = makeelement('tblPr')
      tablestyle = makeelement('tblStyle', attributes={'val': ''})
      tableprops.append(tablestyle)
      tablewidth = makeelement(
          'tblW', attributes={'w': str(tblw), 'type': str(twunit)})
      tableprops.append(tablewidth)
      if len(borders.keys()):
          tableborders = makeelement('tblBorders')
          for b in ['top', 'left', 'bottom', 'right', 'insideH', 'insideV']:
              if b in borders.keys() or 'all' in borders.keys():
                  k = 'all' if 'all' in borders.keys() else b
                  attrs = {}
                  for a in borders[k].keys():
                      attrs[a] = unicode(borders[k][a])
                  borderelem = makeelement(b, attributes=attrs)
                  tableborders.append(borderelem)
          tableprops.append(tableborders)
      tablelook = makeelement('tblLook', attributes={'val': '0400'})
      tableprops.append(tablelook)
      table.append(tableprops)
      # Table Grid
      tablegrid = makeelement('tblGrid')
      for i in range(columns):
          attrs = {'w': str(colw[i]) if colw else '2390'}
          tablegrid.append(makeelement('gridCol', attributes=attrs))
      table.append(tablegrid)
      # Heading Row
      row = makeelement('tr')
      rowprops = makeelement('trPr')
      cnfStyle = makeelement('cnfStyle', attributes={'val': '000000100000'})
      rowprops.append(cnfStyle)
      row.append(rowprops)
      if heading:
          i = 0
          for heading in contents[0]:
              cell = makeelement('tc')
              # Cell properties
              cellprops = makeelement('tcPr')
              if colw:
                  wattr = {'w': str(colw[i]), 'type': cwunit}
              else:
                  wattr = {'w': '0', 'type': 'auto'}
              cellwidth = makeelement('tcW', attributes=wattr)
              cellstyle = makeelement('shd', attributes={'val': 'clear',
                                                         'color': 'auto',
                                                         'fill': 'FFFFFF',
                                                         'themeFill': 'text2',
                                                         'themeFillTint': '99'})
              cellprops.append(cellwidth)
              cellprops.append(cellstyle)
              cell.append(cellprops)
              # Paragraph (Content)
              if not isinstance(heading, (list, tuple)):
                  heading = [heading]
              for h in heading:
                  if isinstance(h, etree._Element):
                      cell.append(h)
                  else:
                      cell.append(paragraph(h, jc='center'))
              row.append(cell)
              i += 1
          table.append(row)
      # Contents Rows
      for contentrow in contents[1 if heading else 0:]:
          row = makeelement('tr')
          i = 0
          for content in contentrow:
              cell = makeelement('tc')
              # Properties
              cellprops = makeelement('tcPr')
              if colw:
                  wattr = {'w': str(colw[i]), 'type': cwunit}
              else:
                  wattr = {'w': '0', 'type': 'auto'}
              cellwidth = makeelement('tcW', attributes=wattr)
              cellprops.append(cellwidth)
              cell.append(cellprops)
              # Paragraph (Content)
              if not isinstance(content, (list, tuple)):
                  content = [content]
              for c in content:
                  if isinstance(c, etree._Element):
                      cell.append(c)
                  else:
                      if celstyle and 'align' in celstyle[i].keys():
                          align = celstyle[i]['align']
                      else:
                          align = 'left'
                      cell.append(paragraph(c, jc=align))
              row.append(cell)
              i += 1
          table.append(row)
      return table