2

I run a daily script checking 50 prices via Beautiful Soup and gspread.

I clear the data using clear() but the script also clears the header title (Column 1 etc) and then starts the data import on the next row after the rows I have cleared. (Row 51)

How can I insert some headers and start the data import from cell A2?

I have tried the following code, but no joy yet

worksheet = wks.worksheet('automated')
worksheet.clear()
worksheet.insert_row(Column A, Column B)
first_row = worksheet.('A2')
first_col = worksheet.('A2')

enter image description here

me9867
  • 1,519
  • 4
  • 25
  • 53

1 Answers1

0

You can use insert_row with the index parameter as 1 for the header:

header = ["header_col1","header_col2"]
index = 1
sheet.insert_row(header, index)

Then use a loop to insert at the second row each data import:

for row in rows_to_import:
    row = ["data_import_col1","data_import_col2"]
    index = 2
    sheet.insert_row(row, index)

You can find the docs for insert_row here.

JMC
  • 11
  • 4