本文整理汇总了Python中odf.table.TableCell类的典型用法代码示例。如果您正苦于以下问题:Python TableCell类的具体用法?Python TableCell怎么用?Python TableCell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TableCell类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_title
def add_title(self, title, width):
row = TableRow()
cell = TableCell(stylename="title")
cell.setAttrNS(TABLENS, "number-columns-spanned", width)
cell.addElement(P(text=title))
row.addElement(cell)
self.sheet.addElement(row)
示例2: insertColumn
def insertColumn(self, sheetname, columnname, columnnumber):
"""Inserts a new empty column into the current doc.
@param sheetname: The name of the sheet to be added to.
@type sheetname: string
@param columnname: The name of the new column to be added
@type columnname: string
@param columnnumber: Where to insert the new column (= how many come before it?)
@type columnnumber: int
"""
sheets = self._doc.spreadsheet.getElementsByType(Table)
for sheet in sheets:
if sheet.getAttribute('name') == sheetname:
rownum = 0
rows = sheet.getElementsByType(TableRow)
for row in rows:
colNum = 0
cells = row.getElementsByType(TableCell)
for cell in cells:
if colNum == columnnumber:
newCell = TableCell()
if rownum == 0:
p = P()
p.addText(unicode(columnname))
newCell.addElement(p)
else:
p = P()
p.addText(unicode(''))
newCell.addElement(p)
row.insertBefore(newCell, cell)
colNum += 1
rownum += 1
示例3: add_row
def add_row( self, _tuple, stylename):
tr = TableRow()
self.table.addElement(tr)
for _c in _tuple:
tc = TableCell( stylename= stylename )
tr.addElement(tc)
p = P(text = _c )
tc.addElement(p)
示例4: addcell
def addcell(tr, val, lestyle):
if val == 'True':
val = "Oui"
if val == 'False':
val = "Non"
tc = TableCell(stylename=lestyle)
tr.addElement(tc)
p = P(text=val)
tc.addElement(p)
示例5: generate_ods
def generate_ods(self, path="/home/apkawa/work/test_desu", group=False):
self.make_style( tablename = self.category.name )
self.add_spanned_row( (u'OOO "Политехник"',), self.head )
head = (
( u'phone:','+7 (812) 312-42-38'),
( u'','+7 (812) 970-42-93'),
( u'email:','[email protected]'),
( u'www:','http://polytechnik.ru'),
('',),
)
self.add_rows( head, self.head )
self.add_row( ( u'Прайс от %s'%date,), self.root_style )
self.add_spanned_row( (self.category.name, ), self.tablemanuf )
self.add_row( ( u'Наименование',u'Описание',u'Цена',), self.tablehead )
manuf = None
type_product = 13
for p in self.price:
if manuf != p.manufacturer_id and p.manufacturer_id != 233:
manuf = p.manufacturer.id
self.add_spanned_row( (p.manufacturer.name,) , self.tablemanuf )
if type_product != p.type_product_id and p.type_product_id != 13:
type_product = p.type_product_id
self.add_spanned_row( ( p.type_product.name,) , self.tablemanuf )
p_desc = p.desc
p_cell = ' %.0f %s'%(p.cell, p.valyuta.desc) if p.cell else ' -'
if p_desc:
self.add_row( ( p.name, p_desc, p_cell ) , self.tablecontents )
elif not p.desc and not p.cell:
p_name = re.sub('(<h4>|</h4>)','',p.name)
self.add_spanned_row( (p_name,), self.tablehead )
else:
tr = TableRow( stylename = self.tablecontents )
self.table.addElement(tr)
p_price = ( p.name, p_cell )
#self.add_cell( pl, tr, self.tablecontents, )#numbercolumnsspanned=2, numberrowsspanned = 1 )
tc = TableCell( stylename= self.tablecontents, numbercolumnsspanned=2, numberrowsspanned = 1 )
tr.addElement(tc)
p = P(text=p_price[0])
tc.addElement(p)
tr.addElement( CoveredTableCell() )
self.add_cell( p_price[1], tr, self.tablecontents )
self.doc.spreadsheet.addElement( self.table )
self.doc.save( path , True)
示例6: write_captions
def write_captions(self, sheet, table):
""" Writes sheet's caption row to table.
"""
row = TableRow()
for caption in sheet.captions:
cell = TableCell()
cell.addElement(P(text=caption))
row.addElement(cell)
table.addElement(row)
示例7: cell
def cell(tr, val, style=None):
print "[cell] type=%s" % str(type(val))
print "[cell] type=%s" % str(val)
if style is None:
tc = TableCell(valuetype=valuetype(val), value=str(val))
else:
tc = TableCell(stylename=style, valuetype=valuetype(val), value=str(val))
tr.addElement(tc)
p = P(stylename=tablecontents, text=str(val))
tc.addElement(p)
示例8: add_spanned_row
def add_spanned_row( self, _tuple, stylename, _count_col_spanned = 3):
tr = TableRow()
self.table.addElement(tr)
for _c in _tuple:
tc = TableCell( stylename= stylename )
tc = TableCell( stylename= stylename, numbercolumnsspanned= _count_col_spanned, numberrowsspanned = 1 )
tr.addElement(tc)
p = P(text = _c )
tc.addElement(p)
tr.addElement( CoveredTableCell() )
示例9: sumtable
def sumtable():
ad = {u"Напряжение" : u' (В)', u"Ток" : u' (А)', u"Мощность" : u' (Вт/c)'}
table = Table()
table.addElement(TableColumn(numbercolumnsrepeated = len(ampl)+1, stylename = tablestyle))
tr = TableRow()
tc = TableCell()
tr.addElement(tc)
for a in ampl:
tr.addElement(ttb(tabletextbold, a))
table.addElement(tr)
for antenna in sorted(dictwire[wire].keys()):
tr = TableRow()
tr.addElement(ttb(tabletextbold, antenna))
table.addElement(tr)
for port in sorted(dictwire[wire][antenna].keys()):
for m in [u"Напряжение", u"Ток", u"Мощность"]:
tr = TableRow()
tr.addElement(ttb(tabletextbold, m+ad[m]))
if port is not None:
tr.addElement(ttb(tabletextbold, port))
table.addElement(tr)
for rg in sorted(dictwire[wire][antenna][port].keys()):
for k in dictwire[wire][antenna][port][rg].keys():
if k != None:
b = sorted(dictwire[wire][antenna][port][rg].keys(), key = len)
else:
b = dictwire[wire][antenna][port][rg].keys()
for distance in b:
tr = TableRow()
tc = TableCell()
try:
p = P(text = distance + ', ' + rg)
except:
p = P(text = rg)
tc.addElement(p)
tr.addElement(tc)
for amplitude in ampl:
try:
if m == u"Мощность":
a = data[dictwire[wire][antenna][port][rg][distance][amplitude][u"Напряжение"]]
amu = a.energy((0,len(a.xvalue)), bytime = True)
amu = '{0:.03e}'.format(amu)
wiretype = a.params['wiretype']
else:
a = data[dictwire[wire][antenna][port][rg][distance][amplitude][m]]
amu = a.max()
amu = '{0:.03f}'.format(amu)
wiretype = a.params['wiretype']
except KeyError:
amu = u'--'
tr.addElement(ttb(tabletext, amu))
table.addElement(tr)
return [table, wiretype]
示例10: make_row
def make_row(self, row):
""" For each item in array add a cell to a row """
tr = TableRow()
for cell_text in row:
try:
#i = int(cell_text)
tc = TableCell(formula=cell_text)
except:
tc = TableCell()
txt = P(text=cell_text)
tc.addElement(txt)
tr.addElement(tc)
return tr
示例11: skills
def skills(self) :
t = self.doc.text
t.addElement(P(text='RELEVANT SKILLS', stylename="Heading"))
table = Table(name="skills-table")
col = 0
skills_cols = int(self.config.fetch('skills_cols'))
table.addElement(TableColumn(numbercolumnsrepeated=skills_cols))
for skill in Resume.skills(self) :
if col % skills_cols == 0 :
tr = TableRow()
table.addElement(tr)
tc = TableCell(valuetype="string")
tc.addElement(P(text=skill,stylename="List"))
tr.addElement(tc)
col += 1
t.addElement(table)
示例12: AddCell
def AddCell(self, attributes=None, rowspan=1, colspan=1):
tc = TableCell(attributes=attributes)
tc.number = self.nextcell
self.nextcell += colspan
tc.setAttribute('numberrowsspanned', str(rowspan))
tc.setAttribute('numbercolumnsrepeated', str(colspan))
tc.setAttribute('numbercolumnsspanned', str(colspan))
self.row.addElement(tc)
return tc
示例13: openSpreadsheet
def openSpreadsheet(self):
"""(Re)Loads the spreadsheet."""
self._doc = load(self._filepath)
rows = self._doc.spreadsheet.getElementsByType(TableRow)
dataWidth = 1
# Determine data-width (as opposed to trailing blank cells)
cells = rows[0].getElementsByType(TableCell)
for cell in cells[1:]:
pl = cell.getElementsByType(P)
if len(pl) > 0 and (pl[0].firstChild) and len(unicode(pl[0].firstChild)) > 0:
dataWidth += 1
else:
break
# Expand out / decompress repeated cells (e.g. number-columns-repeated="2")
for row in rows:
cells = row.getElementsByType(TableCell)
colNum = 0
for cell in cells:
if colNum < dataWidth:
repeated = int(cell.getAttribute('numbercolumnsrepeated') or 0)
pl = cell.getElementsByType(P)
if repeated > 1:
if len(pl) > 0 and (pl[0].firstChild) and len(unicode(pl[0].firstChild)) > 0:
for i in range(repeated):
c = TableCell()
p = P()
p.addText(unicode(pl[0].firstChild))
c.addElement(p)
row.insertBefore(c, cell)
row.removeChild(cell)
else:
for i in range(min(repeated, dataWidth-colNum)):
c = TableCell()
p = P()
p.addText(unicode(''))
c.addElement(p)
row.insertBefore(c, cell)
row.removeChild(cell)
else:
row.removeChild(cell)
colNum += 1
# Add a constant 3 trailing columns
for i in range(3):
c = TableCell()
p = P()
p.addText(unicode(''))
c.addElement(p)
row.addElement(c)
示例14: add_rows
def add_rows(self, _tuple, stylename):
'''
_tuple example
(
('','',), # 1 row
('','','',), # 2 row
)
'''
for _r in _tuple:
tr = TableRow()
self.table.addElement(tr)
for _c in _r:
tc = TableCell( stylename= stylename )
tr.addElement(tc)
p = P(text = _c )
tc.addElement(p)
示例15: addTable
def addTable(self, content, cell_style, column_styles=[]):
""" """
cell_style = getattr(self, cell_style, None)
table = Table()
for style in column_styles:
if "stylename" in style.keys():
style["stylename"] = getattr(self, style["stylename"], None)
table.addElement(TableColumn(**style))
for row in content:
tr = TableRow()
table.addElement(tr)
for cell in row:
tc = TableCell()
tr.addElement(tc)
p = P(stylename=cell_style,text=cell)
tc.addElement(p)
self.document.text.addElement(table)