def append_empty_columns(self, num_new_cols): """Appends the specified number of columns to the right of this table. The columns are empty, except for the possibility of Excel-generated default column headers. The inserted range, including headers, is returned""" # We assume below that at least one column is added # $$$ Decide how to represent empty Ranges() if num_new_cols == 0: return None adjacent = self._adjacent_column_range(num_new_cols) self._reserve_column_space(adjacent) # The insert has helpfully updated xlRanges from underneath us. That is, adjacent has shifted by num_new_cols adjacent = self._adjacent_column_range(num_new_cols) # AutoFilter tables are hard to extend, but easy to promote to a 'real' table if self._from_auto_filter: self._convert_to_listobject_table() # For ListObject tables, putting a value in a column header triggers table-ification magic # Removing the value generates a default column name. Neat. # This accomplishes nothing if this is an AutoFilter table # $$$ update this when slicing is added adj_header_range = Range(adjacent._full_xlRange.Rows(1), with_hidden=True) adj_header_range.set([u" "] * num_new_cols) adj_header_range.set([u""] * num_new_cols) # adjacent is now a subset of the inserted empty space # However, this instance's rData and rHeader attributes are now out of date # We have been possibly using hidden cells above, but want to return a safer range to users # $$$ investigate if updating rData / rHeader is vital return adjacent.excluding_hidden
def append_empty_columns(self, num_new_cols): """Appends the specified number of columns to the right of this table. The columns are empty, except for the possibility of Excel-generated default column headers. The inserted range, including headers, is returned""" # We assume below that at least one column is added # $$$ Decide how to represent empty Ranges() if num_new_cols == 0: return None adjacent = self._adjacent_column_range(num_new_cols) self._reserve_column_space(adjacent) # The insert has helpfully updated xlRanges from underneath us. That is, adjacent has shifted by num_new_cols adjacent = self._adjacent_column_range(num_new_cols) # AutoFilter tables are hard to extend, but easy to promote to a 'real' table if self._from_auto_filter: self._convert_to_listobject_table() # For ListObject tables, putting a value in a column header triggers table-ification magic # Removing the value generates a default column name. Neat. # This accomplishes nothing if this is an AutoFilter table # $$$ update this when slicing is added adj_header_range = Range(adjacent._full_xlRange.Rows(1), with_hidden=True) adj_header_range.set( [u" "] * num_new_cols ) adj_header_range.set( [u""] * num_new_cols ) # adjacent is now a subset of the inserted empty space # However, this instance's rData and rHeader attributes are now out of date # We have been possibly using hidden cells above, but want to return a safer range to users # $$$ investigate if updating rData / rHeader is vital return adjacent.excluding_hidden
def view(self, obj, name=None, to=None): """Writes a Python iterable to an available location in the workbook, with an optional header (name). The optional `to` argument specifies a location hint. If None, the values are written to an empty column on the active sheet. If `to` is a Range, the values are written to it (like Range.set, but with the header prepended) If `to` is a Table, the values are written to a new column in the table.""" # Python version of splatting to cells. if to is None: ws = self.active_sheet # $$$ is this where with_hidden should come from? c = Range(ws.xlWorksheet.Columns(ws._findOpenColumn()), with_hidden=False) elif isinstance(to, table.Table): c = to.append_empty_columns(num_new_cols=1) elif isinstance(to, Range): c = to else: raise ValueError("'to' argument must be a Range, Table, or None") # write a header, this will will cooperate with autofilters. if (name == None): name = "values" if isinstance(obj, basestring): obj = [obj] obj = list(obj) vals = [name] + obj c.set(vals) data_only = c._adjust_unfiltered_size(rows=-1)._offset_unfiltered( rows=1) return data_only
def view(self, obj, name=None, to=None): """Writes a Python iterable to an available location in the workbook, with an optional header (name). The optional `to` argument specifies a location hint. If None, the values are written to an empty column on the active sheet. If `to` is a Range, the values are written to it (like Range.set, but with the header prepended) If `to` is a Table, the values are written to a new column in the table.""" # Python version of splatting to cells. if to is None: ws = self.active_sheet # $$$ is this where with_hidden should come from? c = Range(ws.xlWorksheet.Columns(ws._findOpenColumn()), with_hidden=False) elif isinstance(to, table.Table): c = to.append_empty_columns(num_new_cols=1) elif isinstance(to, Range): c = to else: raise ValueError("'to' argument must be a Range, Table, or None") # write a header, this will will cooperate with autofilters. if (name == None): name = "values" if isinstance(obj, basestring): obj = [ obj ] obj = list(obj) vals = [ name ] + obj c.set(vals) data_only = c._adjust_unfiltered_size(rows=-1)._offset_unfiltered(rows=1) return data_only