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


Python OpenDocumentSpreadsheet.write方法代码示例

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


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

示例1: export_ods

# 需要导入模块: from odf.opendocument import OpenDocumentSpreadsheet [as 别名]
# 或者: from odf.opendocument.OpenDocumentSpreadsheet import write [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

示例2: __call__

# 需要导入模块: from odf.opendocument import OpenDocumentSpreadsheet [as 别名]
# 或者: from odf.opendocument.OpenDocumentSpreadsheet import write [as 别名]
    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,代码行数:14,代码来源:ods.py

示例3: ODSWriter

# 需要导入模块: from odf.opendocument import OpenDocumentSpreadsheet [as 别名]
# 或者: from odf.opendocument.OpenDocumentSpreadsheet import write [as 别名]
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,代码行数:23,代码来源:__init__.py

示例4: to_ods

# 需要导入模块: from odf.opendocument import OpenDocumentSpreadsheet [as 别名]
# 或者: from odf.opendocument.OpenDocumentSpreadsheet import write [as 别名]

#.........这里部分代码省略.........
            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)

        spreadsheet.spreadsheet.addElement(table)
        tmp_ods = tempfile.TemporaryFile()
        spreadsheet.write(tmp_ods)
        tmp_ods.seek(0)
        data = tmp_ods.read()
        os.close(tmp_ods)
        return data
开发者ID:heemanshu,项目名称:swift_juno,代码行数:104,代码来源:profile_model.py

示例5: __init__

# 需要导入模块: from odf.opendocument import OpenDocumentSpreadsheet [as 别名]
# 或者: from odf.opendocument.OpenDocumentSpreadsheet import write [as 别名]

#.........这里部分代码省略.........
        ds = number.DateStyle(name="Date", automaticorder="true",
                              formatsource="language")
        ds.addElement(number.Day())
        ds.addElement(slash)
        ds.addElement(number.Month())
        ds.addElement(slash)
        ds.addElement(number.Year())
        if include_time:
            space = number.Text()
            space.addText(' ')
            colon = number.Text()
            colon.addText(':')
            ds.addElement(space)
            ds.addElement(number.Hours())
            ds.addElement(colon)
            ds.addElement(number.Minutes())
        self.doc.styles.addElement(ds)
        datestyle = Style(name=name, family="table-cell",
                          parentstylename="Default",
                          datastylename=name)
        self.doc.styles.addElement(datestyle)
        return datestyle

    def datecell(self, date, style=None):
        if not style:
            style = self.datestyle
        return TableCell(
            valuetype="date", datevalue=date.isoformat(), stylename=style)

    def datetimecell(self, datetime, style=None):
        if not style:
            style = self.datetimestyle
        return TableCell(
            valuetype="date", datevalue=datetime.isoformat(), stylename=style)

    def _add_currencystyle(self, name="Pounds"):
        """Construct a currency style"""
        cs = number.CurrencyStyle(name=name)
        symbol = number.CurrencySymbol(language="en", country="GB")
        symbol.addText("£")
        cs.addElement(symbol)
        n = number.Number(decimalplaces=2, minintegerdigits=1, grouping="true")
        cs.addElement(n)
        self.doc.styles.addElement(cs)
        currencystyle = Style(name=name, family="table-cell",
                              parentstylename="Default", datastylename=name)
        self.doc.styles.addElement(currencystyle)
        return currencystyle

    def moneycell(self, m, formula=None, style=None):
        a = { "valuetype": "currency",
              "currency": "GBP",
              "stylename": style if style else self.currencystyle,
        }
        if m is not None:
            a["value"] = str(m)
        if formula is not None:
            a["formula"] = formula
        return TableCell(**a)

    @property
    def headerstyle(self):
        if not hasattr(self, "_headerstyle"):
            self._headerstyle = self._add_headerstyle()
        return self._headerstyle

    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

    def headercell(self, text, style=None):
        if not style:
            style = self.headerstyle
        tc = TableCell(valuetype="string", stylename=style)
        tc.addElement(P(stylename=style, text=text))
        return tc

    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]

    def add_table(self, table):
        self.doc.spreadsheet.addElement(table.as_table())

    def as_response(self):
        r = HttpResponse(content_type=self.mimetype)
        if self.filename:
            r['Content-Disposition'] = 'attachment; filename={}'.format(
                self.filename)
        self.doc.write(r)
        return r
开发者ID:sde1000,项目名称:quicktill,代码行数:104,代码来源:spreadsheets.py

示例6: implements

# 需要导入模块: from odf.opendocument import OpenDocumentSpreadsheet [as 别名]
# 或者: from odf.opendocument.OpenDocumentSpreadsheet import write [as 别名]
class OdsExporter:
    implements(IExporter)
    title = u"Export"

    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)

    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)

    def add_breakline(self):
        self._add_row(['\n'])

    def _get_cell(self, label, stylename=None):
        """
        Build a TableCell and adapt the format to the provided label format

        :param label: The data to write (int/float/bool/date/str/unicode)
        :param str stylename: One of the stylenames added in the __init__
        :returns: A TableCell instance
        """
        if stylename is not None:
            cell_to_be_written = TableCell(stylename=stylename)
        else:
            cell_to_be_written = TableCell()
        cell_type = type(label)
        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:
            label = converter_func(label)
        if cell_odf_type != 'string':
            cell_to_be_written.setAttrNS(OFFICENS, cell_odf_value_token, label)
            cell_to_be_written.addElement(P(text=label))
        else:
            lines = label.split('\n')
            for line in lines:
                cell_to_be_written.addElement(P(text=line))
        return cell_to_be_written

    def _add_row(self, labels, cell_style_name=None):
        row = TableRow()
        for label in labels:
            cell = self._get_cell(label, cell_style_name)
            row.addElement(cell)
        self.sheet.addElement(row)

    def add_headers(self, datas):
        self._add_row(datas, "header")

    def add_row(self, datas):
        self._add_row(datas)

    def add_highlighted_row(self, datas):
        self._add_row(datas, "highlight")

    def render(self, f_buf=None):
        if f_buf is None:
            f_buf = cStringIO.StringIO()
        self.book.write(f_buf)
        return f_buf
开发者ID:CroissanceCommune,项目名称:autonomie,代码行数:83,代码来源:ods.py


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