I have a Google Doc that contains placeholders based on A1 notation like %A1%, %B3%, %A3%, and so on.
In a Google Sheet I have values stored in the cell references that match the variable names.
I want to use a script to replace the text in the document from the spreadsheet.
Example Document
I have a %A1% Doc that %B3% placeholders based on %A3% notation
Example Spreadsheet
| A | B | |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | A1 | contains |
Desired Result
I have a Google Doc that contains placeholders based on A1 notation
I have successfully used the following code to make a single replacement but don't know how to loop through all cells in the sheet to make all the replacements.
function myFunction() { var myDoc = DocumentApp.openById('docID') var docBody = myDoc.getActiveSection() var sss = SpreadsheetApp.openById('sheetID'); var x = sss.getRange("A3:A3").getValues() docBody.replaceText('%A3%', x)}