Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9786

Replace text in document using A1 notation as variable names in order to retrieve values stored in those cell references

$
0
0

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

AB
1Google
2
3A1contains

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)} 

Viewing all articles
Browse latest Browse all 9786

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>