当前位置: 首页>>代码示例>>Python>>正文


Python Table.addElement方法代码示例

本文整理汇总了Python中odf.table.Table.addElement方法的典型用法代码示例。如果您正苦于以下问题:Python Table.addElement方法的具体用法?Python Table.addElement怎么用?Python Table.addElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在odf.table.Table的用法示例。


在下文中一共展示了Table.addElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table import addElement [as 别名]
def main(month):

    # Start the table, and describe the columns
    table = Table(name="jixiao")
    table.addElement(TableColumn(numbercolumnsrepeated=16, stylename=widthwide))

    # glue start
    get_udata()
    get_3m_data(month)
    get_total_creat()
    header(table)
    all_odt(table, 0)
    all_odt(table, 1)
    footer(table)
    # glue end

    doc.spreadsheet.addElement(table)

    # save to file

    if not os.path.isdir("output"):
        os.makedirs("output")

    # output/2015-06
    ods_path = "output/%s" % month
    doc.save(ods_path, True)  # odfpy auto add file prefix *.ods
开发者ID:xxd3vin,项目名称:performance,代码行数:28,代码来源:stat.py

示例2: export_ods

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table 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 ()
开发者ID:rpalexis,项目名称:aruca_auf_org,代码行数:35,代码来源:exportateur.py

示例3: create_odf_table

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table import addElement [as 别名]
def create_odf_table(name, data):
    """
    returns an odf table object that has been added a first row containing
    the columns' title

    """
    table = Table(name=name)

    # we need to add columns. The columns itself do not contain the data
    # though. So, we add them only for the first row.
    for c in range(len(data[0])):
        # add table columns
        col = TableColumn(numbercolumnsrepeated=1, stylename="wCol0")
        table.addElement(col)

    for i, item in enumerate(data):

        # the first row contains the table heading, which is colored
        # differently from the rest of the table. Additionally,
        style = "bgrOrange" if i == 0 else None

        logger.debug("row content:%s", item)
        tr = create_odf_table_row(item, style)
        table.addElement(tr)

    return table
开发者ID:yeyintminthuhtut,项目名称:recotak-framework,代码行数:28,代码来源:cOdf.py

示例4: test_percentage

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table 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"'''))
开发者ID:agiacomolli,项目名称:odfpy,代码行数:27,代码来源:testdatastyles.py

示例5: calc

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table import addElement [as 别名]
def calc(title, xlabel, ylabel, xdata, ydata):
    from odf.opendocument import OpenDocumentSpreadsheet
    from odf.text import P
    from odf.table import Table, TableColumn, TableRow, TableCell
    
    outfile = NamedTemporaryFile(
        mode='wb', 
        suffix='.ods',
        prefix='eyesCalc_',
        delete=False)
    doc=OpenDocumentSpreadsheet()
    table = Table(name="ExpEYES {0}".format(time.strftime("%Y-%m-%d %Hh%Mm%Ss")))
    doc.spreadsheet.addElement(table)
    ## add rows into the table
    for i in range(len(xdata)):
        tr = TableRow()
        table.addElement(tr)
        if len(ydata.shape)==1:
            # single y data
            tr.addElement(TableCell(valuetype="float", value=str(xdata[i])))
            tr.addElement(TableCell(valuetype="float", value=str(ydata[i])))
        else:
            # multiple y data
            tr.addElement(TableCell(valuetype="float", value=str(xdata[i])))
            for j in range(ydata.shape[0]):
                tr.addElement(TableCell(valuetype="float", value=str(ydata[j][i])))
    doc.save(outfile)
    outfile.close()
    call("(localc {}&)".format(outfile.name), shell=True)
    return [outfile]
开发者ID:expeyes,项目名称:expeyes-programs,代码行数:32,代码来源:eyesplotter.py

示例6: pictable

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table import addElement [as 别名]
 def pictable(num):
     table = Table()
     table.addElement(TableColumn(numbercolumnsrepeated=2,stylename=tablestyle))
     for word in data[num].params.keys():
         if word in transword and data[num].params[word] != None:
             tr = TableRow()
             tr.addElement(ttb(tabletext, transword[word]))
             tr.addElement(ttb(tabletext, data[num].params[word]))
             table.addElement(tr)
     return table
开发者ID:pinballwizard,项目名称:Cab,代码行数:12,代码来源:odtwrite.py

示例7: sumtable

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table 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]
开发者ID:pinballwizard,项目名称:Cab,代码行数:55,代码来源:odtwrite.py

示例8: ODSSheetWriter

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table import addElement [as 别名]
class ODSSheetWriter(SheetWriter):
    """
    ODS sheet writer
    """

    def set_sheet_name(self, name):
        """initialize the native table"""
        self._native_sheet = Table(name=name)

    def set_size(self, size):
        """not used in this class but used in ods3"""
        pass

    def write_cell(self, row, cell):
        """write a native cell"""
        cell_to_be_written = TableCell()
        cell_type = type(cell)
        cell_odf_type = converter.ODS_WRITE_FORMAT_COVERSION.get(
            cell_type, "string"
        )
        cell_to_be_written.setAttrNS(OFFICENS, "value-type", cell_odf_type)
        cell_odf_value_token = converter.VALUE_TOKEN.get(
            cell_odf_type, "value"
        )
        converter_func = converter.ODS_VALUE_CONVERTERS.get(
            cell_odf_type, None
        )
        if converter_func:
            cell = converter_func(cell)
        if cell_odf_type != "string":
            cell_to_be_written.setAttrNS(OFFICENS, cell_odf_value_token, cell)
            cell_to_be_written.addElement(P(text=cell))
        else:
            lines = cell.split("\n")
            for line in lines:
                cell_to_be_written.addElement(P(text=line))
        row.addElement(cell_to_be_written)

    def write_row(self, array):
        """
        write a row into the file
        """
        row = TableRow()
        self._native_sheet.addElement(row)
        for cell in array:
            self.write_cell(row, cell)

    def close(self):
        """
        This call writes file

        """
        self._native_book.spreadsheet.addElement(self._native_sheet)
开发者ID:pyexcel,项目名称:pyexcel-ods,代码行数:55,代码来源:odsw.py

示例9: inittable

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table import addElement [as 别名]
def inittable(textdoc):
 # Create a style for the table content. One we can modify
 # later in the word processor.
 tablecontents = Style(name="Table Contents", family="paragraph")
 tablecontents.addElement(ParagraphProperties(numberlines="false", linenumber="0"))
 tablecontents.addElement(TextProperties(fontweight="bold"))
 textdoc.styles.addElement(tablecontents)
 widewidth = Style(name="co1", family="table-column")
 widewidth.addElement(TableColumnProperties(columnwidth="9", breakbefore="auto"))
 textdoc.automaticstyles.addElement(widewidth)
 textdoc.styles.addElement(widewidth)
 table = Table( name='test' )
 table.addElement(TableColumn(stylename=widewidth, defaultcellstylename="ce1"))
 return table,tablecontents,textdoc
开发者ID:chiefexb,项目名称:fnscheck,代码行数:16,代码来源:odsmod.py

示例10: skills

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table import addElement [as 别名]
 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)
开发者ID:hobson,项目名称:Util,代码行数:18,代码来源:JITProfile.py

示例11: addTable

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table import addElement [as 别名]
 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)
开发者ID:Guts,项目名称:Metadator,代码行数:19,代码来源:test_md2odt_old.py

示例12: generate

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table import addElement [as 别名]
	def generate(self, target_file):
		""" List each requirement and it's details """

		repo_dir = get_repo_dir()

		rt = RequirementTree()
		rt.load_repository(repo_dir)

		template_file = 'project-estimation-template.ods'

		try:
			template_file_path = os.path.join('templates', template_file)
			template_file_path = os.path.join(repo_dir, template_file_path)
			ods = odf.opendocument.load(template_file_path)
		except Exception as e:
			report_error(1, 'Unable to open template "%s"' % template_file_path)

		if rt._pretty_name:
			ods.meta.addElement(odf.dc.Title(text=rt._pretty_name))
		else:
			ods.meta.addElement(odf.dc.Title(text='[Set name in project.conf]'))

		# Add data sheet
		data_tbl = Table(name="Data")

		# Data header row
		data_tbl.addElement(self.make_row(['Name', 'Hours', 'Cost']))

		items = 1
		for item in rt.get_tree_items():
			if isinstance(item, Requirement) or isinstance(item, RequirementPackage):
				items += 1
				data_tbl.addElement(self.make_row([item._pretty_name, item.estimated_effort, item.estimated_cost]))

		calc_tbl = ods.spreadsheet.firstChild
		calc_2nd_row = calc_tbl.childNodes[3]

		calc_tbl.insertBefore(self.make_row(['Total estimated hours', '=SUM(Data.B2:Data.B%s' % items]), calc_2nd_row)
		calc_tbl.insertBefore(self.make_row(['Total estimated cost', '=SUM(Data.C2:Data.C%s' % items]), calc_2nd_row)

		ods.spreadsheet.addElement(data_tbl)

		try:
			ods.save(target_file, True)
		except:
			report_error(1, 'Unable to write to "%s", is file open?' % target_file)
开发者ID:oliverfields,项目名称:reqy,代码行数:48,代码来源:GenEstimation.py

示例13: ODSSheetWriter

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table import addElement [as 别名]
class ODSSheetWriter(SheetWriter):
    """
    ODS sheet writer
    """
    def set_sheet_name(self, name):
        self.native_sheet = Table(name=name)

    def set_size(self, size):
        pass

    def write_cell(self, row, cell):
        tc = TableCell()
        cell_type = type(cell)
        cell_odf_type = ODS_WRITE_FORMAT_COVERSION.get(cell_type, "string")
        tc.setAttrNS(OFFICENS, "value-type", cell_odf_type)
        cell_odf_value_token = VALUE_TOKEN.get(cell_odf_type, "value")
        converter = ODS_VALUE_CONVERTERS.get(cell_odf_type, None)
        if converter:
            cell = converter(cell)
        if cell_odf_type != 'string':
            tc.setAttrNS(OFFICENS, cell_odf_value_token, cell)
            tc.addElement(P(text=cell))
        else:
            lines = cell.split('\n')
            for line in lines:
                tc.addElement(P(text=line))
        row.addElement(tc)

    def write_row(self, array):
        """
        write a row into the file
        """
        tr = TableRow()
        self.native_sheet.addElement(tr)
        for cell in array:
            self.write_cell(tr, cell)

    def close(self):
        """
        This call writes file

        """
        self.native_book.spreadsheet.addElement(self.native_sheet)
开发者ID:targueriano,项目名称:neuroIFC,代码行数:45,代码来源:__init__.py

示例14: generate_ods

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table 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
开发者ID:C-Element,项目名称:SigeLib,代码行数:33,代码来源:files.py

示例15: ODSSheetWriter

# 需要导入模块: from odf.table import Table [as 别名]
# 或者: from odf.table.Table import addElement [as 别名]
class ODSSheetWriter(SheetWriter):
    """
    ODS sheet writer
    """
    def set_sheet_name(self, name):
        self.native_sheet = Table(name=name)

    def set_size(self, size):
        pass

    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)

    def write_row(self, array):
        """
        write a row into the file
        """
        tr = TableRow()
        self.native_sheet.addElement(tr)
        for x in array:
            self.write_cell(tr, x)

    def close(self):
        """
        This call writes file

        """
        self.native_book.spreadsheet.addElement(self.native_sheet)
开发者ID:fuhrysteve,项目名称:pyexcel-ods,代码行数:41,代码来源:__init__.py


注:本文中的odf.table.Table.addElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。