问题
Following on from this question - I am now unsure how I might be able to target certain paragraphs or elements within the document when using Google Apps Scripts in order to use the batch update method outlined one would need to find the range of the element that required styling.
If there were 10 empty paragraphs (with content of "\n",) in a document - how would it be possible to target the 8th paragraph and get the range values {"startIndex": xx, "endIndex": xx}
relative to the document so they could be used in the batch update?
I have a feeling I am missing something very obvious here.
回答1:
Using Google Docs API and the document ID you can make a documents.get request, which will return you a document resource with a body
field which has a content
field with all the elements in the document, where you can see the "startIndex" and "endIndex".
来源:https://stackoverflow.com/questions/60432342/get-the-ranges-of-the-elements-in-a-google-doc-using-google-apps-script