示例#1
0
    def add_comment_shape(self, root, idx, coord, height, width):
        col, row = coordinate_from_string(coord)
        row -= 1
        column = column_index_from_string(col) - 1
        shape = _shape_factory(row, column, height, width)

        shape.set('id', "_x0000_s%04d" % idx)
        root.append(shape)
示例#2
0
 def translate_col(col_str, cdelta):
     """
     Translate a range col-snippet by the given number of columns
     """
     if col_str.startswith('$'):
         return col_str
     else:
         try:
             return get_column_letter(
                 column_index_from_string(col_str) + cdelta)
         except ValueError:
             raise TranslatorError("Formula out of range")
示例#3
0
    def append(self, iterable):
        """Appends a group of values at the bottom of the current sheet.

        * If it's a list: all values are added in order, starting from the first column
        * If it's a dict: values are assigned to the columns indicated by the keys (numbers or letters)

        :param iterable: list, range or generator, or dict containing values to append
        :type iterable: list|tuple|range|generator or dict

        Usage:

        * append(['This is A1', 'This is B1', 'This is C1'])
        * **or** append({'A' : 'This is A1', 'C' : 'This is C1'})
        * **or** append({1 : 'This is A1', 3 : 'This is C1'})

        :raise: TypeError when iterable is neither a list/tuple nor a dict

        """
        row_idx = self._current_row + 1

        if (isinstance(iterable, (list, tuple, range))
                or isgenerator(iterable)):
            for col_idx, content in enumerate(iterable, 1):
                if isinstance(content, Cell):
                    # compatible with write-only mode
                    cell = content
                    if cell.parent and cell.parent != self:
                        raise ValueError(
                            "Cells cannot be copied from other worksheets")
                    cell.parent = self
                    cell.col_idx = col_idx
                    cell.row = row_idx
                else:
                    cell = Cell(self,
                                row=row_idx,
                                col_idx=col_idx,
                                value=content)
                self._cells[(row_idx, col_idx)] = cell

        elif isinstance(iterable, dict):
            for col_idx, content in iterable.items():
                if isinstance(col_idx, basestring):
                    col_idx = column_index_from_string(col_idx)
                cell = Cell(self, row=row_idx, col_idx=col_idx, value=content)
                self._cells[(row_idx, col_idx)] = cell

        else:
            self._invalid_row(iterable)

        self._current_row = row_idx
示例#4
0
文件: cell.py 项目: j5int/openpyxl2
 def __init__(self,
              worksheet,
              column=None,
              row=None,
              value=None,
              col_idx=None,
              style_array=None):
     super(Cell, self).__init__(worksheet, style_array)
     self.row = row
     """Row number of this cell (1-based)"""
     # _value is the stored value, while value is the displayed value
     self._value = None
     self._hyperlink = None
     self.data_type = 'n'
     if value is not None:
         self.value = value
     self._comment = None
     if column is not None:
         col_idx = column_index_from_string(column)
     self.col_idx = col_idx
     """Column number of this cell (1-based)"""
示例#5
0
 def reindex(self):
     """
     Set boundaries for column definition
     """
     if not all([self.min, self.max]):
         self.min = self.max = column_index_from_string(self.index)