I'm new to Google Docs api and want to be able to add text using the replaceText option. How would I set this up? I am doing this in Python 3.6
1 Answer
Just follow the steps from Google Docs API quickstart using Python. Then try to run this code to insert text using InsertTextRequest method:
requests = [
{
'insertText': {
'location': {
'index': 25,
},
'text': text1
}
},
{
'insertText': {
'location': {
'index': 50,
},
'text': text2
}
},
{
'insertText': {
'location': {
'index': 75,
},
'text': text3
}
},
]
result = service.documents().batchUpdate(
documentId=DOCUMENT_ID, body={'requests': requests}).execute()
To insert text into a document, use the BatchUpdate method and include an InsertTextRequest with the text and location as the payload. It's better to use this suggested method in the documentation.
2 Comments
Slick Slime
Any ideas about how to insert a header and a footer?
rain
Had a followup question to @jess how do we identify the index? Can we use key, value? to make sure if give the heading as key?