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


Python SharedDate.datetime_to_julian方法代码示例

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


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

示例1: DumpWorksheet

# 需要导入模块: from openpyxl.shared.date_time import SharedDate [as 别名]
# 或者: from openpyxl.shared.date_time.SharedDate import datetime_to_julian [as 别名]

#.........这里部分代码省略.........

        fobj.flush()
        fobj.seek(0)

        while True:
            chunk = fobj.read(4096)
            if not chunk:
                break
            self._fileobj.write(chunk)

        fobj.close()

        self._fileobj.flush()

    def _close_content(self):

        doc = self._get_content_generator()
        end_tag(doc, 'sheetData')

        end_tag(doc, 'worksheet')

    def get_dimensions(self):

        if not self._max_col or not self._max_row:
            return 'A1'
        else:
            return '%s%d' % (get_column_letter(self._max_col), (self._max_row))

    def _get_content_generator(self):
        """ XXX: this is ugly, but it allows to resume writing the file 
        even after the handle is closed"""

        # when I'll recreate the XMLGenerator, it will start writing at the
        # begining of the file, erasing previously entered rows, so we have
        # to move to the end of the file before adding new tags
        handle = get_temporary_file(filename=self._fileobj_content_name)
        handle.seek(0, 2)

        doc = XMLGenerator(out=handle)

        return doc

    def append(self, row):

        """
        :param row: iterable containing values to append
        :type row: iterable
        """

        doc = self._get_content_generator()

        self._max_row += 1
        span = len(row)
        self._max_col = max(self._max_col, span)

        row_idx = self._max_row

        attrs = {'r': '%d' % row_idx,
                 'spans': '1:%d' % span}

        start_tag(doc, 'row', attrs)

        for col_idx, cell in enumerate(row):

            if cell is None:
                continue

            coordinate = '%s%d' % (get_column_letter(col_idx + 1), row_idx)
            attributes = {'r': coordinate}

            if isinstance(cell, bool):
                dtype = 'boolean'
            elif isinstance(cell, NUMERIC_TYPES):
                dtype = 'numeric'
            elif isinstance(cell, (datetime.datetime, datetime.date)):
                dtype = 'datetime'
                cell = self._shared_date.datetime_to_julian(cell)
                attributes['s'] = STYLES[dtype]['style']
            elif cell and cell[0] == '=':
                dtype = 'formula'
            else:
                dtype = 'string'
                cell = self._string_builder.add(cell)

            attributes['t'] = STYLES[dtype]['type']

            start_tag(doc, 'c', attributes)

            if dtype == 'formula':
                tag(doc, 'f', body='%s' % cell[1:])
                tag(doc, 'v')
            elif dtype == 'boolean':
                tag(doc, 'v', body='%d' % cell)
            else:
                tag(doc, 'v', body='%s' % cell)

            end_tag(doc, 'c')


        end_tag(doc, 'row')
开发者ID:grlownzl,项目名称:cdisc-share-template-checker,代码行数:104,代码来源:dump_worksheet.py

示例2: DumpWorksheet

# 需要导入模块: from openpyxl.shared.date_time import SharedDate [as 别名]
# 或者: from openpyxl.shared.date_time.SharedDate import datetime_to_julian [as 别名]

#.........这里部分代码省略.........

        self._write_fileobj(self._fileobj_header)
        self._write_fileobj(self._fileobj_content)

        self._fileobj.close()

    def _write_fileobj(self, fobj):

        fobj.flush()
        fobj.seek(0)

        while True:
            chunk = fobj.read(4096)
            if not chunk:
                break
            self._fileobj.write(chunk)

        fobj.close()
        os.remove(fobj.name)

        self._fileobj.flush()

    def _close_header(self):
        
        doc = self.header
        #doc.endDocument()

    def _close_content(self):

        doc = self.doc
        end_tag(doc, 'sheetData')

        end_tag(doc, 'worksheet')
        #doc.endDocument()

    def get_dimensions(self):

        if not self._max_col or not self._max_row:
            return 'A1'
        else:
            return '%s%d' % (get_column_letter(self._max_col), (self._max_row))
            
    def append(self, row):

        """
        :param row: iterable containing values to append
        :type row: iterable
        """

        doc = self.doc

        self._max_row += 1
        span = len(row)
        self._max_col = max(self._max_col, span)

        row_idx = self._max_row

        attrs = {'r': '%d' % row_idx,
                 'spans': '1:%d' % span}

        start_tag(doc, 'row', attrs)

        for col_idx, cell in enumerate(row):

            if cell is None:
                continue

            coordinate = '%s%d' % (get_column_letter(col_idx+1), row_idx) 
            attributes = {'r': coordinate}

            if isinstance(cell, bool):
                dtype = 'boolean'
            elif isinstance(cell, NUMERIC_TYPES):
                dtype = 'numeric'
            elif isinstance(cell, (datetime.datetime, datetime.date)):
                dtype = 'datetime'
                cell = self._shared_date.datetime_to_julian(cell)
                attributes['s'] = STYLES[dtype]['style']
            elif cell and cell[0] == '=':
                dtype = 'formula'
            else:
                dtype = 'string'
                cell = self._string_builder.add(cell)

            attributes['t'] = STYLES[dtype]['type']

            start_tag(doc, 'c', attributes)

            if dtype == 'formula':
                tag(doc, 'f', body = '%s' % cell[1:])
                tag(doc, 'v')
            elif dtype == 'boolean':
                tag(doc, 'v', body = '%d' % cell)
            else:
                tag(doc, 'v', body = '%s' % cell)
            
            end_tag(doc, 'c')


        end_tag(doc, 'row')
开发者ID:chronossc,项目名称:openpyxl,代码行数:104,代码来源:dump_worksheet.py

示例3: DumpWorksheet

# 需要导入模块: from openpyxl.shared.date_time import SharedDate [as 别名]
# 或者: from openpyxl.shared.date_time.SharedDate import datetime_to_julian [as 别名]

#.........这里部分代码省略.........

        fobj = get_temporary_file(filename=fobj_name)

        fobj.flush()
        fobj.seek(0)

        while True:
            chunk = fobj.read(4096)
            if not chunk:
                break
            self._fileobj.write(chunk)

        fobj.close()

        self._fileobj.flush()

    def _close_content(self):

        doc = self._get_content_generator()
        end_tag(doc, "sheetData")

        end_tag(doc, "worksheet")

    def get_dimensions(self):

        if not self._max_col or not self._max_row:
            return "A1"
        else:
            return "%s%d" % (get_column_letter(self._max_col), (self._max_row))

    def _get_content_generator(self):
        """ XXX: this is ugly, but it allows to resume writing the file 
        even after the handle is closed"""

        # when I'll recreate the XMLGenerator, it will start writing at the
        # begining of the file, erasing previously entered rows, so we have
        # to move to the end of the file before adding new tags
        handle = get_temporary_file(filename=self._fileobj_content_name)
        handle.seek(0, 2)

        doc = XMLGenerator(out=handle)

        return doc

    def append(self, row):

        """
        :param row: iterable containing values to append
        :type row: iterable
        """

        doc = self._get_content_generator()

        self._max_row += 1
        span = len(row)
        self._max_col = max(self._max_col, span)

        row_idx = self._max_row

        attrs = {"r": "%d" % row_idx, "spans": "1:%d" % span}

        start_tag(doc, "row", attrs)

        for col_idx, cell in enumerate(row):

            if cell is None:
                continue

            coordinate = "%s%d" % (get_column_letter(col_idx + 1), row_idx)
            attributes = {"r": coordinate}

            if isinstance(cell, bool):
                dtype = "boolean"
            elif isinstance(cell, NUMERIC_TYPES):
                dtype = "numeric"
            elif isinstance(cell, (datetime.datetime, datetime.date)):
                dtype = "datetime"
                cell = self._shared_date.datetime_to_julian(cell)
                attributes["s"] = STYLES[dtype]["style"]
            elif cell and cell[0] == "=":
                dtype = "formula"
            else:
                dtype = "string"
                cell = self._string_builder.add(cell)

            attributes["t"] = STYLES[dtype]["type"]

            start_tag(doc, "c", attributes)

            if dtype == "formula":
                tag(doc, "f", body="%s" % cell[1:])
                tag(doc, "v")
            elif dtype == "boolean":
                tag(doc, "v", body="%d" % cell)
            else:
                tag(doc, "v", body="%s" % cell)

            end_tag(doc, "c")

        end_tag(doc, "row")
开发者ID:OCHA-DAP,项目名称:dataproxy,代码行数:104,代码来源:dump_worksheet.py


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