The Google Docs API supports updating paragraph styles, converting plain paragraphs to bulleted lists, and removing bullets from paragraphs.
Convert a paragraph to a list
A common paragraph formatting operation is converting paragraphs into a bulleted list. Use the CreateParagraphBulletsRequest with a range and optionally a bullet glyph to create a list. All paragraphs that overlap with the provide range will be bulleted. If the specified range overlaps with a table, the bullets will be applied within the table cells.
The following example show a batch request that first inserts text at the start of the document then creates a list out the paragraphs spanning the first 50 characters.
Java
List<Request> requests = new ArrayList<>(); requests.add(new Request().setInsertText(new InsertTextRequest() .setText("Item One\n") .setLocation(new Location().setIndex(1)))); requests.add(new Request().setCreateParagraphBullets( new CreateParagraphBulletsRequest() .setRange(new Range() .setStartIndex(1) .setEndIndex(50)) .setBulletPreset("BULLET_ARROW_DIAMOND_DISC"))); BatchUpdateDocumentRequest body = new BatchUpdateDocumentRequest().setRequests(requests); BatchUpdateDocumentResponse response = docsService.documents() .batchUpdate(DOCUMENT_ID, body).execute();
Python
requests = [ { 'insertText': { 'location': { 'index': 1 }, 'text': 'Item One\n', }}, { 'createParagraphBullets': { 'range': { 'startIndex': 1, 'endIndex': 50 }, 'bulletPreset': 'BULLET_ARROW_DIAMOND_DISC', } } ] result = service.documents().batchUpdate( documentId=DOCUMENT_ID, body={'requests': requests}).execute()
To remove a paragraph list, use DeleteParagraphBulletsRequest.
Java
List<Request> requests = new ArrayList<>(); requests.add(new Request().setDeleteParagraphBullets( new DeleteParagraphBulletsRequest() .setRange(new Range() .setStartIndex(1) .setEndIndex(50)))); BatchUpdateDocumentRequest body = new BatchUpdateDocumentRequest().setRequests(requests); BatchUpdateDocumentResponse response = docsService.documents() .batchUpdate(DOCUMENT_ID, body).execute();
Python
requests = [ { 'deleteParagraphBullets': { 'range': { 'startIndex': 1, 'endIndex': 50 }, } } ] result = service.documents().batchUpdate( documentId=DOCUMENT_ID, body={'requests': requests}).execute()