'Upload worksheet instance with gspread
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)
?
Solution 1:[1]
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_IDis copied to the Spreadsheet ofTARGET_SHEET_ID.
Reference:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tanaike |
