I\'ve got a pre-existing spreadsheet hosted on google docs. Each month I update this document. I\'ve got a template workseet in the spreadseet that I\'d like to clone and then
(Feb 2017) Rephrasing question with current terminology: How do you copy a Google Sheet template, then modify it (the copy) programmatically? Short answer: it's much easier with current Google APIs, specifically the Google Drive v3 API and the Google Sheets v4 API, and you can do it with any language supported by the Google APIs Client Libraries.
The latest Sheets API provides features not available in older releases, namely giving developers programmatic access to a Sheet as if you were using the user interface (UI), i.e., create frozen rows, cell formatting, resize rows/columns, add pivot tables, cell validation, create charts, etc.
As you can guess, the Sheets API is primarily for programmatically accessing spreadsheet operations & functionality as described above, but to perform file-level access such as copying a template Sheet, use the Google Drive API instead.
Pseudocode (Python) to copy a file (Sheet) using the Drive API (assuming we first search for the most recently modified file with the template name, hence the orderBy and selection of the first result [0] below):
TMPLFILE = 'my Sheets template'
tmpl = DRIVE.files().list(q="name='%s'" % TMPLFILE).execute().get('files')[0]
NEW_SHEET = {'name': 'Sheets data, Feb 2017'}
SHEET_ID = DRIVE.files().copy(body=NEW_SHEET, fileId=tmpl['id']).execute().get('id')
Pseudocode to read values from a SQL database (SQLite) and write them to the new Sheet created above (starting from cell 'A1' as "upper-left") as if a user entered the values from the UI (so formulae can be applied, etc.):
cxn = sqlite3.connect('db.sqlite')
cur = cxn.cursor()
rows = cur.execute('SELECT * FROM data').fetchall()
cxn.close()
DATA = {'values': rows}
SHEETS.spreadsheets().values().update(spreadsheetId=SHEET_ID,
range='A1', body=DATA, valueInputOption='USER_ENTERED').execute()
If you're relatively new to modern Google APIs, I have a (somewhat dated but) user-friendly intro video for you. There are 2 videos after that maybe useful too, including one that demonstrates using the Drive API. Those are videos 2, 3, and 4 in this playlist. Videos 23 & 25 are another pair featuring the Drive and Sheets APIs.
All newer videos can be found in this playlist where you'll find another pair of videos featuring the Sheets API plus a reprise of the "template copying" code above but copying a Slides template which is then modified with the Slides API) instead (video 2).
As mentioned in another answer, you can also use Google Apps Script to do something similar if you prefer that environment vs. using REST APIs, although Apps Script currently uses older APIs. Also there are few outstanding bugs that may make it a bit more challenging (specifically this one and this one).