diff --git a/gspread/worksheet.py b/gspread/worksheet.py index ae5712d5c..0e3caf31e 100644 --- a/gspread/worksheet.py +++ b/gspread/worksheet.py @@ -569,7 +569,6 @@ def get_all_records( return [] keys = entire_sheet[head - 1] - self.column_headers = keys values = entire_sheet[head:] if expected_headers is None: @@ -615,6 +614,8 @@ def append_records( rows: List[Dict[str, Any]], ignore_extra_headers: bool = False, default_blank: Any = "", + header_row: Optional[int] = None, + value_input_option: Optional[ValueInputOption] = None, ) -> None: """Appends records as rows to your data range. @@ -627,10 +628,11 @@ def append_records( :param default_blank: The value to use for missing columns in the data. Defaults to an empty string. :type default_blank: Any + :raises GSpreadException: If extra headers are found in the data set and `ignore_extra_headers` is False. """ - cols = self.column_headers + cols = self.get_column_headers(header_row) insert_rows = [] for row in rows: if not set(row).issubset(set(cols)) and not ignore_extra_headers: @@ -641,16 +643,15 @@ def append_records( insert_row.append(row.get(col, default_blank)) insert_rows.append(insert_row) - self.append_rows( - insert_rows, - value_input_option=ValueInputOption.user_entered, - ) + self.append_rows(insert_rows, value_input_option=value_input_option) def append_record( self, row: Dict[str, Any], ignore_extra_headers: bool = False, default_blank: Any = "", + header_row: Optional[int] = None, + value_input_option: Optional[ValueInputOption] = None, ) -> None: """Appends a dict as a row to your data range. @@ -670,6 +671,8 @@ def append_record( [row], ignore_extra_headers=ignore_extra_headers, default_blank=default_blank, + header_row=header_row, + value_input_option=value_input_option, ) def insert_records( @@ -678,6 +681,8 @@ def insert_records( ignore_extra_headers: bool = False, default_blank: Any = "", insert_row: int = 2, + header_row: Optional[int] = None, + value_input_option: Optional[ValueInputOption] = None, ) -> None: """Insert records as rows to your data range at the stated row. @@ -715,7 +720,8 @@ def insert_records( self.insert_rows( insert_rows, row=insert_row, - value_input_option=ValueInputOption.user_entered, + value_input_option=value_input_option, + header_row=header_row, ) def insert_record( @@ -724,6 +730,8 @@ def insert_record( ignore_extra_headers: bool = False, default_blank: Any = "", insert_row: int = 2, + header_row: Optional[int] = None, + value_input_option: Optional[ValueInputOption] = None, ) -> None: """Insert a dict as rows to your data range at the stated row. @@ -752,6 +760,8 @@ def insert_record( ignore_extra_headers=ignore_extra_headers, insert_row=insert_row, default_blank=default_blank, + header_row=header_row, + value_input_option=value_input_option, ) def get_all_cells(self) -> List[Cell]: