Adds multiple new cols to the worksheet at specified index and populates them with values. :param list values: List of col lists. a list of lists, with the lists each containing one col's values. Increases the number of rows if there are more values than colu
(
self,
values: Sequence[Sequence[Union[str, int, float]]],
col: int = 1,
value_input_option: ValueInputOption = ValueInputOption.raw,
inherit_from_before: bool = False,
)
| 1976 | return res |
| 1977 | |
| 1978 | def insert_cols( |
| 1979 | self, |
| 1980 | values: Sequence[Sequence[Union[str, int, float]]], |
| 1981 | col: int = 1, |
| 1982 | value_input_option: ValueInputOption = ValueInputOption.raw, |
| 1983 | inherit_from_before: bool = False, |
| 1984 | ) -> JSONResponse: |
| 1985 | """Adds multiple new cols to the worksheet at specified index and |
| 1986 | populates them with values. |
| 1987 | |
| 1988 | :param list values: List of col lists. a list of lists, with the lists |
| 1989 | each containing one col's values. Increases the number of rows |
| 1990 | if there are more values than columns. |
| 1991 | :param int col: Start col to update (one-based). Defaults to 1 (one). |
| 1992 | :param str value_input_option: (optional) Determines how input data |
| 1993 | should be interpreted. Possible values are ``ValueInputOption.raw`` |
| 1994 | or ``ValueInputOption.user_entered``. |
| 1995 | See `ValueInputOption`_ in the Sheets API. |
| 1996 | :type value_input_option: :class:`~gspread.utils.ValueInputOption` |
| 1997 | :param bool inherit_from_before: (optional) If True, new columns will |
| 1998 | inherit their properties from the previous column. Defaults to |
| 1999 | False, meaning that new columns acquire the properties of the |
| 2000 | column immediately after them. |
| 2001 | |
| 2002 | .. warning:: |
| 2003 | |
| 2004 | `inherit_from_before` must be False if adding at the left edge |
| 2005 | of a spreadsheet (`col=1`), and must be True if adding at the |
| 2006 | right edge of the spreadsheet. |
| 2007 | """ |
| 2008 | |
| 2009 | if inherit_from_before and col == 1: |
| 2010 | raise GSpreadException( |
| 2011 | "inherit_from_before cannot be used when inserting column(s) at the left edge of a spreadsheet" |
| 2012 | ) |
| 2013 | |
| 2014 | insert_dimension_body = { |
| 2015 | "requests": [ |
| 2016 | { |
| 2017 | "insertDimension": { |
| 2018 | "range": { |
| 2019 | "sheetId": self.id, |
| 2020 | "dimension": Dimension.cols, |
| 2021 | "startIndex": col - 1, |
| 2022 | "endIndex": len(values) + col - 1, |
| 2023 | }, |
| 2024 | "inheritFromBefore": inherit_from_before, |
| 2025 | } |
| 2026 | } |
| 2027 | ] |
| 2028 | } |
| 2029 | |
| 2030 | self.client.batch_update(self.spreadsheet_id, insert_dimension_body) |
| 2031 | |
| 2032 | range_label = absolute_range_name(self.title, rowcol_to_a1(1, col)) |
| 2033 | |
| 2034 | params: ParamsType = {"valueInputOption": value_input_option} |
| 2035 |