@@ -45,6 +45,20 @@ function findAndReplace(documentId, findTextToReplacementMap) {
45
45
const requests = [ ] ;
46
46
for ( const findText in findTextToReplacementMap ) {
47
47
const replaceText = findTextToReplacementMap [ findText ] ;
48
+ // One option for replacing all text is to specify all tab IDs.
49
+ const request = {
50
+ replaceAllText : {
51
+ containsText : {
52
+ text : findText ,
53
+ matchCase : true
54
+ } ,
55
+ replaceText : replaceText ,
56
+ tabsCriteria : {
57
+ tabIds : [ TAB_ID_1 , TAB_ID_2 , TAB_ID_3 ] ,
58
+ }
59
+ }
60
+ } ;
61
+ // Another option is to omit TabsCriteria if you are replacing across all tabs.
48
62
const request = {
49
63
replaceAllText : {
50
64
containsText : {
@@ -73,8 +87,8 @@ function findAndReplace(documentId, findTextToReplacementMap) {
73
87
74
88
// [START docs_insert_and_style_text]
75
89
/**
76
- * Insert text at the beginning of the document and then style the inserted
77
- * text.
90
+ * Insert text at the beginning of the first tab in the document and then style
91
+ * the inserted text.
78
92
* @param {string } documentId The document the text is inserted into.
79
93
* @param {string } text The text to insert into the document.
80
94
* @return {Object } replies
@@ -84,7 +98,10 @@ function insertAndStyleText(documentId, text) {
84
98
const requests = [ {
85
99
insertText : {
86
100
location : {
87
- index : 1
101
+ index : 1 ,
102
+ // A tab can be specified using its ID. When omitted, the request is
103
+ // applied to the first tab.
104
+ // tabId: TAB_ID
88
105
} ,
89
106
text : text
90
107
}
@@ -119,16 +136,17 @@ function insertAndStyleText(documentId, text) {
119
136
120
137
// [START docs_read_first_paragraph]
121
138
/**
122
- * Read the first paragraph of the body of a document.
139
+ * Read the first paragraph of the first tab in a document.
123
140
* @param {string } documentId The ID of the document to read.
124
141
* @return {Object } paragraphText
125
142
* @see https://developers.google.com/docs/api/reference/rest/v1/documents/get
126
143
*/
127
144
function readFirstParagraph ( documentId ) {
128
145
try {
129
146
// Get the document using document ID
130
- const document = Docs . Documents . get ( documentId ) ;
131
- const bodyElements = document . body . content ;
147
+ const document = Docs . Documents . get ( { 'includeTabsContent' : true } , documentId ) ;
148
+ const firstTab = document . tabs [ 0 ] ;
149
+ const bodyElements = firstTab . documentTab . body . content ;
132
150
for ( let i = 0 ; i < bodyElements . length ; i ++ ) {
133
151
const structuralElement = bodyElements [ i ] ;
134
152
// Print the first paragraph text present in document
0 commit comments