简体   繁体   中英

How do I copy value from a goole sheet to a google doc using scripts for long format?

I have:

  1. A Sheet with Columns for A, B, and C.
  2. A Doc with a templatized text that includes A, B, and C values.
  3. A output Doc where I want to have the templatized text multiple times, adjusting for A, B and C.

Is there a way to get a script that does this?

Reading your steps I can see that you are very close to finishing your project. You only need to use the following methods.

First you would need to open and read your spreadsheet. You can gather all the data with a combination of Spreadsheet.getDataRange() and Range.getValues() . You will end up with an array with the A, B and C columns.

Furthermore you would need to open the Doc template. This step is very similar to the previous one, you can achieve it by using Document.getBody() and Body.getText() .

Now you have the data and the template, you only need to join them together. To manage it, run the data rows in a loop substituting the placeholders in the template with the data rows. This way you will end up with an output array as big as your spreadsheet data. At this point you can write it down on the output Doc by using Document.getCursor() and Position.insertText() with each output line.

Please, feel free to ask me any doubts to better help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM