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


Python opendocument.OpenDocumentSpreadsheet类代码示例

本文整理汇总了Python中odf.opendocument.OpenDocumentSpreadsheet的典型用法代码示例。如果您正苦于以下问题:Python OpenDocumentSpreadsheet类的具体用法?Python OpenDocumentSpreadsheet怎么用?Python OpenDocumentSpreadsheet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: output_reqset

    def output_reqset(self, reqset, reqscont):

        # Because of a problem with the current OpenOffice versions,
        # there is the need to sometimes arrange requirements as rows
        # and sometimes as columns:
        # It is not possible to define the range of a list input as a
        # row: it must be a column.
        # The order dictionary holds the number - which can be
        # computed in a row or column.
        def create_reqs_index(srqes):
            sreqs_index = {}
            cnt = 0
            for req in sreqs:
                sreqs_index[req] = cnt
                cnt += 1
            return sreqs_index

        # The topological sort is needed.
        sreqs = topological_sort(self.topic_set.reqset)

        # Create the row / column index of each requirement
        self.sreqs_index = create_reqs_index(sreqs)

        # Create and save the document
        calcdoc = OpenDocumentSpreadsheet()
        self.create_meta(calcdoc, reqscont)
        self.create_styles(calcdoc)
        self.create_costs_sheet(calcdoc, sreqs)
        self.create_deps_sheet(calcdoc, sreqs)
        self.create_sums_sheet(calcdoc, sreqs)
        self.create_constants_sheet(calcdoc)
        self.create_result_sheet(calcdoc, sreqs)
        calcdoc.save(self.output_filename, True)
开发者ID:vakaras,项目名称:rmtoo-old,代码行数:33,代码来源:oopricing1.py

示例2: export_ods

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,代码行数:33,代码来源:exportateur.py

示例3: generate_ods

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,代码行数:31,代码来源:files.py

示例4: test_percentage

    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,代码行数:25,代码来源:testdatastyles.py

示例5: calc

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,代码行数:30,代码来源:eyesplotter.py

示例6: _toODSFile

def _toODSFile(odf_table_list, filename):

    doc = OpenDocumentSpreadsheet()
    for t in odf_table_list:
        doc.spreadsheet.addElement(t)

    doc.save('/tmp/' + filename, True)
    return file('/tmp/' + filename + '.ods')
开发者ID:zxdvd,项目名称:snoek,代码行数:8,代码来源:views.py

示例7: __call__

    def __call__(self, spreadsheet, file):
        """ Writes all data from spreadsheet into file.
        """

        doc = OpenDocumentSpreadsheet()

        for sheet in spreadsheet:
            table = Table(name=sheet.name)
            self.write_sheet(sheet, table)
            doc.spreadsheet.addElement(table)

        doc.write(file)
开发者ID:vakaras,项目名称:pysheets,代码行数:12,代码来源:ods.py

示例8: __init__

 def __init__(self):
     self.book = OpenDocumentSpreadsheet()
     self.book.automaticstyles.addElement(TITLE_STYLE)
     self.book.automaticstyles.addElement(HEADER_STYLE)
     self.book.automaticstyles.addElement(HIGHLIGHT_STYLE)
     self.sheet = Table(name=self.title)
     self.book.spreadsheet.addElement(self.sheet)
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:7,代码来源:ods.py

示例9: topic_set_pre

 def topic_set_pre(self, topics_set):
     '''Document setup and output.
        Because for this document a very specific sort order
        must be implemented, everything must be done here explicitly -
        the executor interface can only partially be used.'''
     self.__calcdoc = OpenDocumentSpreadsheet()
     self.__create_meta()
     self.__create_styles()
开发者ID:CrypticGator,项目名称:rmtoo,代码行数:8,代码来源:oopricing1.py

示例10: ODSWriter

class ODSWriter(BookWriter):
    """
    open document spreadsheet writer

    """
    def __init__(self, file, **keywords):
        BookWriter.__init__(self, file, **keywords)
        self.native_book = OpenDocumentSpreadsheet()

    def create_sheet(self, name):
        """
        write a row into the file
        """
        return ODSSheetWriter(self.native_book, None, name)

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

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

示例11: test_ooo_ns

    def test_ooo_ns(self):
        """ Check that ooo exists in namespace declarations """
        calcdoc = OpenDocumentSpreadsheet()
        table = odf.table.Table(name="Costs")
        forms = odf.office.Forms()
        form = odf.form.Form(
           controlimplementation="ooo:com.sun.star.form.component.Form")
        lb = odf.form.Listbox(
           controlimplementation="ooo:com.sun.star.form.component.ListBox", dropdown="true", id="control1")
        form.addElement(lb)
        forms.addElement(form)
        table.addElement(forms)

        # One empty line
        tr = odf.table.TableRow()
        table.addElement(tr)

        tr = odf.table.TableRow()
        # One empty cell
        cell = odf.table.TableCell()
        tr.addElement(cell)

        cell = odf.table.TableCell()

        draw = odf.draw.Control(
        control="control1", height="0.1126in", width="0.798in",
        x="0.0303in", y="0.0205in", endcelladdress="Costs.B2",
        endx="0.8283in", endy="0.1331in")

        cell.addElement(draw)
        tr.addElement(cell)
        table.addElement(tr)

        calcdoc.spreadsheet.addElement(table)
        result = unicode(calcdoc.contentxml(),'utf-8')
        self.assertNotEqual(-1, result.find(u'''xmlns:ooo="http://openoffice.org/2004/office"'''))
开发者ID:BrickXu,项目名称:odfpy,代码行数:36,代码来源:testform.py

示例12: __init__

    def __init__(self, filename=None):
        self.doc = OpenDocumentSpreadsheet()
        self.filename = filename

        # Add some common styles
        self.tablecontents = Style(name="Table Contents", family="paragraph")
        self.tablecontents.addElement(
            ParagraphProperties(numberlines="false", linenumber="0"))
        self.doc.styles.addElement(self.tablecontents)

        self.currencystyle = self._add_currencystyle()

        self.boldcurrencystyle = Style(name="BoldPounds", family="table-cell",
                                       parentstylename=self.currencystyle)
        self.boldcurrencystyle.addElement(
            TextProperties(fontweight="bold"))
        self.doc.styles.addElement(self.boldcurrencystyle)

        self.boldtextstyle = Style(name="BoldText", family="table-cell",
                                   parentstylename=self.tablecontents)
        self.boldtextstyle.addElement(TextProperties(fontweight="bold"))
        self.doc.styles.addElement(self.boldtextstyle)

        self._widthstyles = {}
开发者ID:sde1000,项目名称:quicktill,代码行数:24,代码来源:spreadsheets.py

示例13: to_ods

    def to_ods(self, *selection):
        if not ODFLIB_INSTALLED:
            raise ODFLIBNotInstalled(_("odfpy not installed."))
        if self.fcn_list:
            stat_list = self.fcn_list[:]
            order_text = "   Ordered by: " + self.sort_type + "\n"
        else:
            stat_list = self.stats.keys()
            order_text = "   Random listing order was used\n"
        for s in selection:
            stat_list, __ = self.eval_print_amount(s, stat_list, "")
        spreadsheet = OpenDocumentSpreadsheet()
        table = Table(name="Profile")
        for fn in self.files:
            tcf = TableCell()
            tcf.addElement(P(text=fn))
            trf = TableRow()
            trf.addElement(tcf)
            table.addElement(trf)

        tc_summary = TableCell()
        summary_text = (
            "%d function calls (%d primitive calls) in %.6f \
                        seconds"
            % (self.total_calls, self.prim_calls, self.total_tt)
        )
        tc_summary.addElement(P(text=summary_text))
        tr_summary = TableRow()
        tr_summary.addElement(tc_summary)
        table.addElement(tr_summary)

        tc_order = TableCell()
        tc_order.addElement(P(text=order_text))
        tr_order = TableRow()
        tr_order.addElement(tc_order)
        table.addElement(tr_order)

        tr_header = TableRow()
        tc_cc = TableCell()
        tc_cc.addElement(P(text="Total Call Count"))
        tr_header.addElement(tc_cc)

        tc_pc = TableCell()
        tc_pc.addElement(P(text="Primitive Call Count"))
        tr_header.addElement(tc_pc)

        tc_tt = TableCell()
        tc_tt.addElement(P(text="Total Time(seconds)"))
        tr_header.addElement(tc_tt)

        tc_pc = TableCell()
        tc_pc.addElement(P(text="Time Per call(seconds)"))
        tr_header.addElement(tc_pc)

        tc_ct = TableCell()
        tc_ct.addElement(P(text="Cumulative Time(seconds)"))
        tr_header.addElement(tc_ct)

        tc_pt = TableCell()
        tc_pt.addElement(P(text="Cumulative Time per call(seconds)"))
        tr_header.addElement(tc_pt)

        tc_nfl = TableCell()
        tc_nfl.addElement(P(text="filename:lineno(function)"))
        tr_header.addElement(tc_nfl)

        table.addElement(tr_header)

        for func in stat_list:
            cc, nc, tt, ct, __ = self.stats[func]
            tr_header = TableRow()
            tc_nc = TableCell()
            tc_nc.addElement(P(text=nc))
            tr_header.addElement(tc_nc)

            tc_pc = TableCell()
            tc_pc.addElement(P(text=cc))
            tr_header.addElement(tc_pc)

            tc_tt = TableCell()
            tc_tt.addElement(P(text=tt))
            tr_header.addElement(tc_tt)

            tc_tpc = TableCell()
            tc_tpc.addElement(P(text=(None if nc == 0 else float(tt) / nc)))
            tr_header.addElement(tc_tpc)

            tc_ct = TableCell()
            tc_ct.addElement(P(text=ct))
            tr_header.addElement(tc_ct)

            tc_tpt = TableCell()
            tc_tpt.addElement(P(text=(None if cc == 0 else float(ct) / cc)))
            tr_header.addElement(tc_tpt)

            tc_nfl = TableCell()
            tc_nfl.addElement(P(text=func))
            tr_header.addElement(tc_nfl)
            table.addElement(tr_header)

#.........这里部分代码省略.........
开发者ID:heemanshu,项目名称:swift_juno,代码行数:101,代码来源:profile_model.py

示例14: save

  def save(self, filename, i_max = None, j_max = None):
    ''' save table in ods format '''

    if not i_max: i_max = self.table.i_max
    if not j_max: j_max = self.table.j_max

    # update cells text
    self.table.updateTable(i_max, j_max)

    # create new odf spreadsheet
    odfdoc = OpenDocumentSpreadsheet()

    # set direction style
    rtl = Style(name = "dir", family = "table")
    if self.table.direction == 'rtl':
      rtl.addElement(TableProperties(writingmode="rl-tb"))
    odfdoc.automaticstyles.addElement(rtl)

    # create the table
    table = Table(name = "sheet 1", stylename = 'dir')
    
    # default style
    ts = Style(name = "ts", family = "table-cell")
    ts.addElement(TextProperties(fontfamily = SodsCell().font_family, fontsize = SodsCell().font_size))
    odfdoc.styles.addElement(ts)

    # create columns
    for j in range(1, j_max):
      colname = "col" + str(j)
      c = self.table.getCellAt(0, j)
      width = c.column_width
      cs = Style(name = colname, family = "table-column")
      cs.addElement(TableColumnProperties(columnwidth = width, breakbefore = "auto"))
      odfdoc.automaticstyles.addElement(cs)

      table.addElement(TableColumn(stylename = colname, defaultcellstylename = "ts"))

    # make sure values are up to date
    # loop and update the cells value
    for i in range(1, i_max):
      # create new ods row
      tr = TableRow()
      table.addElement(tr)

      # create default data styles for dates and numbers
      ncs = NumberStyle(name="ncs")
      ncs.addElement(Number(decimalplaces="2", minintegerdigits="1", grouping="true"))
      odfdoc.styles.addElement(ncs)

      ncs2 = NumberStyle(name="ncs2")
      ncs2.addElement(Number(decimalplaces="0", minintegerdigits="1", grouping="false"))
      odfdoc.styles.addElement(ncs2)

      dcs = DateStyle(name="dcs")
      dcs.addElement(Year(style='long'))
      dcs.addElement(Text(text = u'-'))
      dcs.addElement(Month(style='long'))
      dcs.addElement(Text(text = u'-'))
      dcs.addElement(Day(style='long'))
      odfdoc.styles.addElement(dcs)

      for j in range(1, j_max):
        # update the cell text and condition
        cell = self.table.encodeColName(j) + str(i)
        c = self.table.getCellAt(i, j)

        # chose datastylename
        if c.value_type == 'date':
          datastylename = "dcs"
        else:
          if c.format == "":
            datastylename = "ncs2"
          if c.format == "#,##0.00":
            datastylename = "ncs"

        # get cell style id
        if (c.condition):
          style_id = (datastylename + c.color + c.font_size + c.font_family + 
            c.background_color + c.border_top + c.border_bottom + 
            c.border_left + c.border_right + 
            c.condition_color + c.condition_background_color)
        else:
          style_id = (datastylename + c.color + c.font_size + c.font_family + 
            c.background_color + c.border_top + c.border_bottom + 
            c.border_left + c.border_right)

        # set ods style
        style_name = self.getStyle(c, cell, datastylename, style_id, odfdoc)

        # create new ods cell
        if (c.formula and c.formula[0] == '=' and c.formula[:4] != '=uni'):
          if self.table.isFloat(c.value):
            tc = TableCell(valuetype = c.value_type, 
              formula = c.formula, value = float(c.value), stylename = style_name)
          else:
            tc = TableCell(valuetype = c.value_type, 
              formula = c.formula, 
              value = 0, stylename = style_name)
        elif (c.value_type == 'date'):
          tc = TableCell(valuetype = c.value_type, 
#.........这里部分代码省略.........
开发者ID:yaacov,项目名称:simple-odspy,代码行数:101,代码来源:sodsods.py

示例15: OpenDocumentSpreadsheet

		for variable, examinee, examiners in possibilities:
			if variables[variable]:
				examinees[examinee] = examiners

for date, times in examinations:
	for time, possibilities in times:
		for variable, examinee, examiners in possibilities:
			if not examinee in examinees and not examinee in undefined:
				undefined[examinee] = ["without appointment", examiners]

'''
for examinee in undefined:
	print examinee
'''

output = OpenDocumentSpreadsheet()

middle_center = Style(name="middle_center", family="table-cell")
middle_center.addElement(TableCellProperties(verticalalign="middle"))
middle_center.addElement(ParagraphProperties(textalign="center"))
output.styles.addElement(middle_center)

middle_left = Style(name="middle_left", family="table-cell")
middle_left.addElement(TableCellProperties(verticalalign="middle"))
middle_left.addElement(ParagraphProperties(textalign="left"))
output.styles.addElement(middle_left)

date_style = Style(name="date", family="table-column")
date_style.addElement(TableColumnProperties(columnwidth="5cm"))
output.automaticstyles.addElement(date_style)
开发者ID:xdsopl,项目名称:timetable,代码行数:30,代码来源:timetable.py


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