i am trying to create a google document that has a paragraph automatically generated from data on a google spreadsheet. most of the information i have found shows how to create one document or one page for each set of data but i need to generate one paragraph and have the script create as many pages as is necessary. this is my first google script (and i’m new to scripting in general) so there may be some obvious errors.
here is what i have for the script so far:
function scriptListGen() {
var mySheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var firstName = mySheet.getRange("B3").getValue();
var lastName = mySheet.getRange("C3").getValue();
var dispo1 = "Prescription Left With Dr.";
var dispo2 = "Prescription Recieved";
var dispo3 = "Prescription Denied";
var notes = "Notes:";
var date = "Date:";
var content = firstName + " " + lastName + " " + dispo1 + dispo2 + dispo3 + notes;
var templateDocID = ScriptProperties.getProperty("listTemplateDocID");
var docID = DocsList.getFileById(templateDocID).makeCopy().getId();
var doc = DocumentApp.openById(docID);
var body = doc.getActiveSection();
body.insertParagraph(1, content);
body.insertHorizontalRule(2);
}
any help is much appreciated.
Evan,
I’m not quite sure what you mean by ‘add as many pages as possible’. But assuming you mean that you want to have the information from your spreadsheet flow from one page to the next as needed, I think you’ll want to use
Here’s some code I’m using that does a similar process.
So the code will iterate through tabs I selected, and then go through the various rows to pull out information. The information is formatted using some pre-defined headingstyles into a Document.
Hope this helps.