Adds multiple rows to the worksheet at the specified index and populates them with values. :param list values: List of row lists. a list of lists, with the lists each containing one row's values. Widens the worksheet if there are more values than columns.
(
self,
values: Sequence[Sequence[Union[str, int, float]]],
row: int = 1,
value_input_option: ValueInputOption = ValueInputOption.raw,
inherit_from_before: bool = False,
)
| 1904 | ) |
| 1905 | |
| 1906 | def insert_rows( |
| 1907 | self, |
| 1908 | values: Sequence[Sequence[Union[str, int, float]]], |
| 1909 | row: int = 1, |
| 1910 | value_input_option: ValueInputOption = ValueInputOption.raw, |
| 1911 | inherit_from_before: bool = False, |
| 1912 | ) -> JSONResponse: |
| 1913 | """Adds multiple rows to the worksheet at the specified index and |
| 1914 | populates them with values. |
| 1915 | |
| 1916 | :param list values: List of row lists. a list of lists, with the lists |
| 1917 | each containing one row's values. Widens the worksheet if there are |
| 1918 | more values than columns. |
| 1919 | :param int row: Start row to update (one-based). Defaults to 1 (one). |
| 1920 | :param str value_input_option: (optional) Determines how input data |
| 1921 | should be interpreted. Possible values are ``ValueInputOption.raw`` |
| 1922 | or ``ValueInputOption.user_entered``. |
| 1923 | See `ValueInputOption`_ in the Sheets API. |
| 1924 | :type value_input_option: :class:`~gspread.utils.ValueInputOption` |
| 1925 | :param bool inherit_from_before: (optional) If true, new rows will |
| 1926 | inherit their properties from the previous row. Defaults to False, |
| 1927 | meaning that new rows acquire the properties of the row immediately |
| 1928 | after them. |
| 1929 | |
| 1930 | .. warning:: |
| 1931 | |
| 1932 | `inherit_from_before` must be False when adding rows to the top |
| 1933 | of a spreadsheet (`row=1`), and must be True when adding to |
| 1934 | the bottom of the spreadsheet. |
| 1935 | """ |
| 1936 | |
| 1937 | # can't insert row on sheet with colon ':' |
| 1938 | # in its name, see issue: https://issuetracker.google.com/issues/36761154 |
| 1939 | if ":" in self.title: |
| 1940 | raise GSpreadException( |
| 1941 | "can't insert row in worksheet with colon ':' in its name. See issue: https://issuetracker.google.com/issues/36761154" |
| 1942 | ) |
| 1943 | |
| 1944 | if inherit_from_before and row == 1: |
| 1945 | raise GSpreadException( |
| 1946 | "inherit_from_before cannot be used when inserting row(s) at the top of a spreadsheet" |
| 1947 | ) |
| 1948 | |
| 1949 | insert_dimension_body = { |
| 1950 | "requests": [ |
| 1951 | { |
| 1952 | "insertDimension": { |
| 1953 | "range": { |
| 1954 | "sheetId": self.id, |
| 1955 | "dimension": Dimension.rows, |
| 1956 | "startIndex": row - 1, |
| 1957 | "endIndex": len(values) + row - 1, |
| 1958 | }, |
| 1959 | "inheritFromBefore": inherit_from_before, |
| 1960 | } |
| 1961 | } |
| 1962 | ] |
| 1963 | } |
no test coverage detected