11#!/usr/bin/env python2.6
2+ # -*- coding: utf-8 -*-
23'''
34Open and modify Microsoft Word 2007 docx files (called 'OpenXML' and 'Office OpenXML' by Microsoft)
45
@@ -188,8 +189,15 @@ def heading(headingtext,headinglevel):
188189 # Return the combined paragraph
189190 return paragraph
190191
191- def table (contents ):
192- '''Get a list of lists, return a table'''
192+ def table (contents , heading = True ):
193+ '''Get a list of lists, return a table
194+
195+ @param list contents: A list of lists describing contents
196+ @param bool heading: Tells whether first line should be threated as heading
197+ or not
198+
199+ @return lxml.etree: Generated XML etree element
200+ '''
193201 table = makeelement ('tbl' )
194202 columns = len (contents [0 ][0 ])
195203 # Table properties
@@ -211,21 +219,22 @@ def table(contents):
211219 cnfStyle = makeelement ('cnfStyle' ,attributes = {'val' :'000000100000' })
212220 rowprops .append (cnfStyle )
213221 row .append (rowprops )
214- for heading in contents [0 ]:
215- cell = makeelement ('tc' )
216- # Cell properties
217- cellprops = makeelement ('tcPr' )
218- cellwidth = makeelement ('tcW' ,attributes = {'w' :'2390' ,'type' :'dxa' })
219- cellstyle = makeelement ('shd' ,attributes = {'val' :'clear' ,'color' :'auto' ,'fill' :'548DD4' ,'themeFill' :'text2' ,'themeFillTint' :'99' })
220- cellprops .append (cellwidth )
221- cellprops .append (cellstyle )
222- cell .append (cellprops )
223- # Paragraph (Content)
224- cell .append (paragraph (heading ))
225- row .append (cell )
226- table .append (row )
227- # Contents Rows
228- for contentrow in contents [1 :]:
222+ if heading :
223+ for heading in contents [0 ]:
224+ cell = makeelement ('tc' )
225+ # Cell properties
226+ cellprops = makeelement ('tcPr' )
227+ cellwidth = makeelement ('tcW' ,attributes = {'w' :'2390' ,'type' :'dxa' })
228+ cellstyle = makeelement ('shd' ,attributes = {'val' :'clear' ,'color' :'auto' ,'fill' :'548DD4' ,'themeFill' :'text2' ,'themeFillTint' :'99' })
229+ cellprops .append (cellwidth )
230+ cellprops .append (cellstyle )
231+ cell .append (cellprops )
232+ # Paragraph (Content)
233+ cell .append (paragraph (heading ))
234+ row .append (cell )
235+ table .append (row )
236+ # Contents Rows
237+ for contentrow in contents [1 if heading else 0 :]:
229238 row = makeelement ('tr' )
230239 for content in contentrow :
231240 cell = makeelement ('tc' )
0 commit comments