本文整理汇总了Python中odf.table.TableCell.addElement方法的典型用法代码示例。如果您正苦于以下问题:Python TableCell.addElement方法的具体用法?Python TableCell.addElement怎么用?Python TableCell.addElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类odf.table.TableCell
的用法示例。
在下文中一共展示了TableCell.addElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export_ods
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
def export_ods (headers, data):
doc = OpenDocumentSpreadsheet()
style = Style(name="Large number", family="table-cell")
style.addElement(TextProperties(fontfamily="Arial", fontsize="15pt"))
doc.styles.addElement(style)
widewidth = Style(name="co1", family="table-column")
widewidth.addElement(TableColumnProperties(columnwidth="2.8cm", breakbefore="auto"))
doc.automaticstyles.addElement(widewidth)
table = Table()
if len (headers) > 0:
tr = TableRow ()
table.addElement (tr)
for item in headers:
tc = TableCell ()
tr.addElement (tc)
p = P(stylename = style, text = txt(item))
tc.addElement (p)
for line in data:
tr = TableRow ()
table.addElement (tr)
for item in line:
tc = TableCell ()
tr.addElement (tc)
p = P (stylename = style, text = txt(item))
tc.addElement (p)
doc.spreadsheet.addElement(table)
buffer = StringIO ()
doc.write(buffer)
return buffer.getvalue ()
示例2: insertColumn
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
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: generate_ods
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
def generate_ods(data):
"""
Generate a ODS file.
:param data: list-like of dict with the data.
:return:
"""
doc = OpenDocumentSpreadsheet()
table = Table()
tr = TableRow()
colautowidth = Style(name="co1", family="table-column")
colautowidth.addElement(TableColumnProperties(useoptimalcolumnwidth=True))
doc.automaticstyles.addElement(colautowidth)
for column in data[0].keys():
table.addElement(TableColumn(stylename=colautowidth))
tc = TableCell(valuetype="string", value=column)
tc.addElement(P(text=column))
tr.addElement(tc)
table.addElement(tr)
for row in data:
tr = TableRow()
for column in row.keys():
tc = TableCell(valuetype="string", value=row[column])
tc.addElement(P(text=row[column]))
tr.addElement(tc)
table.addElement(tr)
file = os.path.join(tempfile.gettempdir(), 'SIGE' +
datetime.now().strftime('%Y%m%d%H%M%S%f') + '.ods')
doc.spreadsheet.addElement(table)
print(doc.automaticstyles.childNodes[0].attributes)
doc.save(file)
return file
示例4: add_title
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
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)
示例5: add_row
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
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)
示例6: addcell
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
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)
示例7: generate_ods
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
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)
示例8: cell
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
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)
示例9: add_spanned_row
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
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() )
示例10: write_captions
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
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)
示例11: sumtable
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
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]
示例12: write_cell
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
def write_cell(self, row, x):
tc = TableCell()
x_type = type(x)
x_odf_type = ODS_WRITE_FORMAT_COVERSION.get(x_type, "string")
tc.setAttrNS(OFFICENS, "value-type", x_odf_type)
x_odf_value_token = VALUE_TOKEN.get(x_odf_type, "value")
converter = ODS_VALUE_CONVERTERS.get(x_odf_type, None)
if converter:
x = converter(x)
if x_odf_type != 'string':
tc.setAttrNS(OFFICENS, x_odf_value_token, x)
tc.addElement(P(text=x))
row.addElement(tc)
示例13: addrow
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
def addrow(row,table,tablecontents):
tr = TableRow()
table.addElement(tr)
for rr in row:
if str(type(rr))=="<type 'unicode'>":
tc = TableCell(valuetype="string")
tr.addElement(tc)
p = P(stylename=tablecontents,text=rr)
tc.addElement(p)
elif str(type(rr))=="<type 'float'>" or str(type(rr))=="<type 'int'>" or str(type(rr))=="<class 'decimal.Decimal'>" :
tc = TableCell(valuetype="float",value=rr)
tr.addElement(tc)
elif str(type(rr))=="<type 'NoneType'>":
tc = TableCell(valuetype="string")
tr.addElement(tc)
p = P(stylename=tablecontents,text=unicode(' ',PWENC))
tc.addElement(p)
elif str(type(rr))=="<type 'datetime.datetime'>":
tc = TableCell(valuetype="string")
tr.addElement(tc)
p = P(stylename=tablecontents,text=unicode(rr.strftime("%d.%m.%Y") ,PWENC))
tc.addElement(p)
else:
print str(type(rr)),rr
tc = TableCell(valuetype="string")
tr.addElement(tc)
p = P(stylename=tablecontents,text=unicode(rr,PWENC))
tc.addElement(p)
tr.addElement(tc)
tr.addElement(tc)
return table
示例14: NameDatePair
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
def NameDatePair(self, a, b) :
table = Table(name="t")
table.addElement(TableColumn(numbercolumnsrepeated="1",
stylename="widecolumn"))
table.addElement(TableColumn(numbercolumnsrepeated="1",
stylename="narrowcolumn"))
tr = TableRow()
tc = TableCell(valuetype="string")
tc.addElement(P(text=a,stylename="Name"))
tr.addElement(tc)
tc = TableCell(valuetype="string")
tc.addElement(P(text=b,stylename="RightItalic"))
tr.addElement(tc)
table.addElement(tr)
return table
示例15: make_row
# 需要导入模块: from odf.table import TableCell [as 别名]
# 或者: from odf.table.TableCell import addElement [as 别名]
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