Created
February 17, 2019 18:25
-
-
Save imankulov/8cd6fb7497d8714389ad230932193563 to your computer and use it in GitHub Desktop.
Generating documents from Google Sheets with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pandas | |
docxtpl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment