I have a template worksheet in a spreadsheet that I need to duplicate to another spreadsheet. How can I achieve this with gspread?
gs = gspread.oauth()
template_sh = gs.open_by_key(TEMPLATE_SHEET_ID)
template_ws = template_sh.worksheet('Template')
target_sh = gs.open_by_key(TARGET_SHEET_ID)
Is there anything like
target_sh.upload(template_ws)
?
CodePudding user response:
In order to copy the specification sheet in TEMPLATE_SHEET_ID
to the target Spreadsheet of TARGET_SHEET_ID
, how about the following sample script?
Sample script:
TEMPLATE_SHEET_ID = "###" # Please set Spreadsheet ID.
TARGET_SHEET_ID = "###" # Please set Spreadsheet ID.
gs = gspread.oauth()
template_sh = gs.open_by_key(TEMPLATE_SHEET_ID)
template_ws = template_sh.worksheet('Template')
res = template_ws.copy_to(TARGET_SHEET_ID)
- When this script is run, "Template" sheet of
TEMPLATE_SHEET_ID
is copied to the Spreadsheet ofTARGET_SHEET_ID
.