Skip to content

Instantly share code, notes, and snippets.

@imankulov
Created February 17, 2019 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imankulov/8cd6fb7497d8714389ad230932193563 to your computer and use it in GitHub Desktop.
Save imankulov/8cd6fb7497d8714389ad230932193563 to your computer and use it in GitHub Desktop.
Generating documents from Google Sheets with Python
import pandas as pd
from docxtpl import DocxTemplate
SHEET_URL='https://docs.google.com/spreadsheets/d/1Kvb5bmm2qZWEH4I5hJYZMEuIBU-CCw_ivyv_jjB1w4w/export?exportFormat=csv'
TEMPLATE = 'quote.docx'
def save_quote(quote_id):
df = pd.read_csv(SHEET_URL, index_col='QuoteID')
context = dict(df.loc[quote_id])
doc = DocxTemplate(TEMPLATE)
doc.render(context)
doc.save(f'quote_{quote_id}.docx')
if __name__ == '__main__':
import sys
save_quote(int(sys.argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment