本文整理汇总了Python中odf.style.Style.addElement方法的典型用法代码示例。如果您正苦于以下问题:Python Style.addElement方法的具体用法?Python Style.addElement怎么用?Python Style.addElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类odf.style.Style
的用法示例。
在下文中一共展示了Style.addElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: export_ods
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style 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: colwidth
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def colwidth(self, width):
if width not in self._widthstyles:
w = Style(name="W{}".format(width), family="table-column")
w.addElement(TableColumnProperties(columnwidth=width))
self.doc.automaticstyles.addElement(w)
self._widthstyles[width] = w
return self._widthstyles[width]
示例3: generate_ods
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style 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: test_percentage
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def test_percentage(self):
""" Test that an automatic style can refer to a PercentageStyle as a datastylename """
doc = OpenDocumentSpreadsheet()
nonze = PercentageStyle(name='N11')
nonze.addElement(Number(decimalplaces='2', minintegerdigits='1'))
nonze.addElement(Text(text='%'))
doc.automaticstyles.addElement(nonze)
pourcent = Style(name='pourcent', family='table-cell', datastylename='N11')
pourcent.addElement(ParagraphProperties(textalign='center'))
pourcent.addElement(TextProperties(attributes={'fontsize':"10pt",'fontweight':"bold", 'color':"#000000" }))
doc.automaticstyles.addElement(pourcent)
table = Table(name='sheet1')
tr = TableRow()
tc = TableCell(formula='=AVERAGE(C4:CB62)/2',stylename='pourcent', valuetype='percentage')
tr.addElement(tc)
table.addElement(tr)
doc.spreadsheet.addElement(table)
doc.save("TEST.odt")
self.saved = True
d = load("TEST.odt")
result = d.contentxml()
self.assertNotEqual(-1, result.find(u'''<number:percentage-style'''))
self.assertNotEqual(-1, result.find(u'''style:data-style-name="N11"'''))
self.assertNotEqual(-1, result.find(u'''style:name="pourcent"'''))
示例5: __handleFrameStyleRotated
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def __handleFrameStyleRotated(self, text_data):
style_name = "box%s%s%s%s%sRotated" % (
text_data.face,
text_data.size,
text_data.line_space,
text_data.letter_space,
text_data.justification,
)
if not style_name in self.font_styles:
frame_style = Style(name=style_name, family="paragraph")
frame_style.addElement(
ParagraphProperties(
linespacing="%spt" % text_data.line_space, textalign=self.convertTextAlign(text_data.justification)
)
)
frame_style.addElement(
TextProperties(
letterspacing="%spt" % text_data.letter_space,
fontstyle=self.convertFontStyle(text_data.style),
fontweight=self.convertFontWeight(text_data.weight),
fontsize="%spt" % text_data.size,
fontfamily=str(text_data.face),
)
)
self.document.automaticstyles.addElement(frame_style)
self.font_styles.append(style_name)
return style_name
示例6: _add_headerstyle
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def _add_headerstyle(self):
header = Style(name="ColumnHeader", family="table-cell")
header.addElement(
ParagraphProperties(textalign="center"))
header.addElement(
TextProperties(fontweight="bold"))
self.doc.styles.addElement(header)
return header
示例7: addParagraphStyle
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def addParagraphStyle(self, id, name, paragraph_properties={}, text_properties={}):
""" """
style = Style(name=name, family="paragraph")
if len(paragraph_properties) > 0:
style.addElement(ParagraphProperties(**paragraph_properties))
if len(text_properties) > 0:
style.addElement(TextProperties(**text_properties))
setattr(self, id, style)
self.document.styles.addElement(style)
示例8: newPage
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def newPage(self, page_data):
master_name = self.__handlePageMaster(page_data)
page_style_name = "%sPage" % master_name
if not page_style_name in self.page_styles:
page_style = Style(name=page_style_name, family="paragraph", masterpagename=master_name)
page_style.addElement(ParagraphProperties(breakbefore="page"))
self.document.automaticstyles.addElement(page_style)
new_page = P(stylename=page_style_name)
self.document.text.addElement(new_page)
return new_page
示例9: setup
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def setup(self):
odt = self.generator
s = odt.styles
h1s = Style(name="Heading 1", family="paragraph")
h1s.addElement(
TextProperties(
attributes={'fontsize': "24pt",
'fontweight': "bold"}
)
)
s.addElement(h1s)
self.h1s = h1s
示例10: __setDefaultStyle
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def __setDefaultStyle(self):
DefaultStyle = Style(name="Standard", family='paragraph')
DefaultStyle.addElement(TextProperties(
fontfamily='FreeSans',
fontsize='10pt'))
DefaultStyle.addElement(ParagraphProperties(
margintop='0.423cm',
marginbottom='0.212cm'))
self.__doc.styles.addElement(DefaultStyle)
''' Text Body '''
txt = Style(name='text_20_body', family='paragraph', parentstylename='Standard')
self.__doc.styles.addElement(txt)
示例11: odt_write
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def odt_write(object, filename, introduction=None, lmf2odt=lmf_to_odt, items=lambda lexical_entry: lexical_entry.get_lexeme(), sort_order=None, paradigms=False, reverse=False):
"""! @brief Write a document file.
@param object The LMF instance to convert into document output format.
@param filename The name of the document file to write with full path, for instance 'user/output.odt'.
@param introduction The name of the text file with full path containing the introduction of the document, for instance 'user/config/introduction.txt'. Default value is None.
@param lmf2odt A function giving the mapping from LMF representation information that must be written to ODT commands, in a defined order. Default value is 'lmf_to_odt' function defined in 'pylmflib/config/odt.py'. Please refer to it as an example.
@param items Lambda function giving the item to sort. Default value is 'lambda lexical_entry: lexical_entry.get_lexeme()', which means that the items to sort are lexemes.
@param sort_order Python list. Default value is 'None', which means that the document output is alphabetically ordered.
@param paradigms A boolean value to introduce paradigms in document or not.
@param reverse A boolean value to set if a reverse dictionary is wanted.
"""
import string
if sort_order is None:
# Lowercase and uppercase letters must have the same rank
sort_order = dict([(c, ord(c)) for c in string.lowercase])
up = dict([(c, ord(c) + 32) for c in string.uppercase])
sort_order.update(up)
sort_order.update({'':0, ' ':0})
textdoc = OpenDocumentText()
# Styles
s = textdoc.styles
h1style = Style(name="Heading 1", family="paragraph")
h1style.addElement(TextProperties(attributes={'fontsize':"24pt", 'fontweight':"bold" }))
s.addElement(h1style)
# An automatic style
boldstyle = Style(name="Bold", family="text")
boldprop = TextProperties(fontweight="bold", fontname="Arial", fontsize="8pt")
boldstyle.addElement(boldprop)
textdoc.automaticstyles.addElement(boldstyle)
# Parse LMF values
if object.__class__.__name__ == "LexicalResource":
for lexicon in object.get_lexicons():
# Document title
h = H(outlinelevel=1, stylename=h1style, text=lexicon.get_id())
textdoc.text.addElement(h)
# Plain paragraph
p = P(text=lexicon.get_label())
# Text
boldpart = Span(stylename=boldstyle, text="Test. ")
p.addElement(boldpart)
# Introduction
if introduction is not None:
p.addText(file_read(introduction))
textdoc.text.addElement(p)
# Page break
#
# Text body
lmf2odt(lexicon, textdoc, items, sort_order, paradigms, reverse)
else:
raise OutputError(object, "Object to write must be a Lexical Resource.")
textdoc.save(filename)
示例12: _create_style
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def _create_style(name, family=None, **kwargs):
"""Helper function for creating a new style."""
if family == 'paragraph' and 'marginbottom' not in kwargs:
kwargs['marginbottom'] = '.5cm'
style = Style(name=name, family=family)
# Extract paragraph properties.
kwargs_par = {}
keys = sorted(kwargs.keys())
for k in keys:
if 'margin' in k:
kwargs_par[k] = kwargs.pop(k)
style.addElement(TextProperties(**kwargs))
if kwargs_par:
style.addElement(ParagraphProperties(**kwargs_par))
return style
示例13: _create_styles
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def _create_styles( self ):
#Creating new ruby style
self.ruby_style_name = "RubyMy"
my_ruby_style = Style( name=self.ruby_style_name, family="ruby" )
my_ruby_style.addElement(
RubyProperties( rubyalign = "center",
rubyposition = "above" ) )
self.doc.automaticstyles.addElement( my_ruby_style )
#Create dotted style
self.dot_style_name = "DottedMy"
my_dotted_style = Style( name = self.dot_style_name,
family="text" )
my_dotted_style.addElement(
TextProperties( textemphasize="dot above" ) )
self.doc.automaticstyles.addElement( my_dotted_style )
示例14: add_title_page
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def add_title_page(self, odt, title):
# Requirements for <project name>
# <project description>
#
# Author: <stakeholder name>
# <date>
#
# <document description>
# Title
titlestyle = Style(name="TitleStyle",family="text")
titlestyle.addElement(TextProperties(attributes={'fontweight':"bold", 'fontsize':'36pt'}))
odt.automaticstyles.addElement(titlestyle)
titlespan = Span(stylename=titlestyle, text=_('Requirements for "%s"') % title)
p = P(text='')
p.addElement(titlespan)
odt.text.addElement(p)
示例15: add_attribute_row
# 需要导入模块: from odf.style import Style [as 别名]
# 或者: from odf.style.Style import addElement [as 别名]
def add_attribute_row(self, table, key, value):
""" Add a two cell row to the table """
boldstyle = Style(name="Bold",family="text")
boldstyle.addElement(TextProperties(attributes={'fontweight':"bold"}))
title_span = Span(stylename=boldstyle, text=key)
pt = P(text='')
pt.addElement(title_span)
tr = TableRow()
tc = TableCell(valuetype='string')
tc.addElement(pt)
tr.addElement(tc)
tc = TableCell(valuetype='string')
tc.addElement(P(text=value))
tr.addElement(tc)
table.addElement(tr)