Thank you for the incredible tutorial. It was very easy to follow and helped someone like myself, who had never coded with Apps Scripts, to get a sense of how the language works and be able to personalize my script for my intended application. I've already build off of your script to automate the filling of multiple documents at the clinic I work at, which will dramatically decrease the burden on our doctors and nurses, and allow them overall more time to focus on patient care. Thank you for helping us make that difference!
This tutorial really helped my company save time and mistakes on filling out paperwork. The autofill feature we created with this, and his "Adding Custom Menus" video took some tinkering, but we got it to work, and everyone's delighted at this low cost, low maintenance solution. Thank you Jeff!
I just started a role at a new company and docs and sheets are a major part of the workflow. This gives me a great quick way to automate things without standing up a full Python or Node.js application to do it.
Thanks Jeff. This will come really handy for us. 1. Data collected through google form. 2. Data dumps into spreadsheet 3. Use this script to create a letter for sending out to clients
The UI in Google Sheets is slightly updated from when this was recorded, but even with my rudimentary coding knowledge I was able to modify this to work. THANK YOU, this is amazing.
@Jeff Everhart out of curiosity, is there a way to use template literals to have the scrip generate a new folder, and store the document in that folder?
That is actually a very good tutorial! I first watched a crappy one called "Autofill Google Doc Template from Google Sheets | Google Apps Script" from the channel Outright System... The guy just stole your code, without even giving you credit, and pasted it without any explanation! Some people have no shame and are awful educators, really. But thank YOU for the great explanation and time you took to actually teach us!
This is just what I need! Hopefully I can execute this on my own template, I don’t really understand any programming language but I’ve surviving by copying codes out of tutorials and browsing the net. Thank you so much for sharing your knowledge!
Thank you so much for this tutorial! It is so much easier to understand and adapt to different situations when you take the time to explain what every line does instead of just importing a pile of code from some website.
How come this guy only has 2.2k followers? Doing such a great job sharing this type of content so carefully so anybody just stepping in this would be able to understand? thank you So much man!! God bless you!
This was my first dive into Google Scripts or any code for the matter. And it was a successful one! This saved me a lot of hassle and put me on a way of Excel / Sheets skill development and put a lot of ideas into my mind about working with code. You are truly a special kind of person for doing this, at least in my life! Thank you very much.
This is brilliant! Any chance you can add the script for when there is a choice of templates to pull on depending on a criteria specified in the form????
Thank you for a great tutorial. This is going to save me and my husband so much time with filling out legal documents for our real estate business. I am a complete novice when it comes to coding, but this was very easy to follow and understand. The only thing I had a problem with was an error saying that the document was inaccessible. But, I realized that I had been using a .docx (Microsoft Word) document and that google docs didn’t recognize it within the code, even though it could open the file and edit it. Just thought I’d mention that in case anyone else had the same problem.
Your tutorials are excellent, you do a great job of explaining as you go along. I originally used your prior video, "Auto Fill Google Doc from Google Form Using Google Apps Script," but found on occasion it would fail to generate the doc, without explanation (i.e. someone submits a form, it goes to the spreadsheet, but the doc just doesn't happen.) The method you demo here allowed me to set up a manual workaround for those occurrences.
Thank you a million Jeffrey! I had a question. What if an employee has two rows (for example an employee has two different jobs, each with their own separate pay and hours, etc.)? Is there a way to have details from two separate rows populate into a document, separately? Reply
Thanks for this Jeff. I want the rows of the sheet to populate sections of a single document, not create multiple documents. Which line of code to I delete or modify so that the loop sends the data of each row to the single document?
Great video. I have a question though. Your Google app script primarily works for one column and multiple rows in google doc. Can you help us with Google app script where it generates multiple columns and rows table on Google doc using the data that is available on a single row of Google sheet?
thank you! you really put in the effort to explain everything so that beginners like me can understand the reasoning behind each line and therefore customize the script later on.
This was incredibly easy to follow! Thank you so much! I have several cells that have formulas that rely on other cells. If the target cells are blank, it returns a "" or blank. This script creates documents for all of these rows. Using your tutorial, I was able to add a line of script that if the first name was blank it moves on!
At this point, I'm honestly more used to your voice on 0.5x speed haha. Again, thanks so much for this tutorial, it has helped my business a lot to automate some of our systems. I'm officially crowning you as the dad of Google Sheets haha!
Hey Jeff, Thanks so much for this ! Out of interest how would i take a cell that has a URL in it and replace a tag in the doc with the image rather than the URL ?
Thank you for this resource! This may be a silly question - This is my first attempt at exploring apps script or coding. Can I do this for just one row of data at a time? My spreadsheet is form responses and some of them require a template checklist of next steps for the team, but not all. It's constantly collecting responses. I do have a column that records whether or not a template needs to be generated.
I keep getting the error: Exception: The parameters (String) don't match the method signature for DocumentApp.Body.replaceText. Any idea what may need to be fixed? I have everything plugged in as you do in the video.
Thank you for the great tutorial. I was wondering if it is possible to have the filled Docs merge into a single Doc, rather a separate doc for each employee. Thanks
Thanks so, so much for this. I'm just dipping my toes into coding and wouldn't have been able to do this sort of thing without your helpful, clear instructions and provision of the template! I made some mistakes in my version of it, but because I was able to rewatch your tutorial, I learned not only what I did wrong, but how to identify where in the code the mistake was made.
This video is the best! you explained it so well. I needed to add a few more pieces to my code. Having gone into this with no idea how to use AppScript did not matter! This video pointed out to me in the right way to ask my questions online and I was able to get everything to work! Thank you Jeff!
This was so helpful!! Thank you - I created a merge doc weeks ago and went back to your website to find out about formatting (currency)... and found the answer in you FAQ! Massive help - thank you!
Great video! simpel and to the point. One question, what if I have a chunk of text and tables in my template, and I want to make it appear or dissappear in the output doc based on a clickbox in the sheets docs. How would I do that? I have a template with descriptions for different services, but I need that segment of text/tables only if the service is procured. So I want to have a list of services in sheets, click on the ones the customer procures.
Absolutely fantastic video, thank you so much! I just have one question. I have hyperlinks in one column of my spreadsheet, how can I put those in the document? I tried doing it just like your tutorial, but it replaces only the text, not its formatting (i.e. hyperlinks). Is there a workaround?
Thank you Jeff for the great tutorial. I had one question, is there a way to create an if statement to read a value in a row to see which google doc template the script should use? I started it with a function with if statements having it read the value in row[x] === "PARTICULAR LANGUAGE" then return the value for the googleDocTemplate = DriveApp.getFileById ('FILE ID'). Sorry if this is a bit confusing. I have multiple templates for different employee variables and want to write the code once versus have multiple codes for each template. I want the script to do the work.
Thank you so much. Concise, clear and competent instructions! A great contrast to a lot of other help out here. It's helped me sort out a formatting issue for an online form. What I would really love is to email the resulting doc (form submission output file) as a PDF to myself/my colleague. I have not been able to resolve the variable for the output filename... thanks for any help you are able to give.
Thank you so much for taking the time with these tutorials. Very straight to the point and an easy steps. It's really helping me a lot with my business automations! THANK YOU!
I have an issue. rows.forEach --> when I try to execute it says Rows is not defined. The data is not being returned as an Array so I cannot use the .forEach. ? Make sense?
Hi Jeff, amazing video and great teaching skills. I was wondering if instead of creating google docs we are able to create PDFs named with a field and saved them to a google shared drive?
Excellent tutorial for sheets to docs. Do you have a tutorial for sheets to slides? I thought I could replace the "docs" Apps with "slides" Apps but didn't work. This is the first time using Google Apps Script. thanks
Great tutorial and really easy to follow. Helps solve a problem I've been having 🙂 Is there coding that could be used to also automatically share (view only) the resulting doc with someone in domain if their email address was also a field in the sheet?
Jeff, This tutorial video was great! I know nothing about coding, but I followed your video and it worked! I have one big question - in my sheet at the bottom of each column, I have a SUM function. This SUM function row will be moving further down the sheet as I add more content to the sheet. How can I prevent it from reading this row?? Thank you!
Thank you for your instructions. They are very well done. Do you have any options for how to output just the date from a cell in the month/day/year format?
tried googling this for you and found a stackoverflow article, search this: differences-between-getrange-getdatarange-and-getactiverange here's part of the answer: " getRange() has multiple implementations. Sheet.getRange(row, column) Sheet.getRange(row, column, numRows) Sheet.getRange(row, column, numRows, numColumns) Sheet.getRange(a1notation) " So you'd have to play around with the getRange parameters in your code, to select a part of the range instead of it all.
Hi Jeff, thanks for such wholesome content! Id just like to ask for my case, I have a table template in Google doc, and I want to insert a new row automatically once there are 2 products or more, how can I do it, please? Any help will be much appreciated, thanks in advance!
This is such a great tool! I have managed to get this working for a couple of uses however I was wondering a few things: 1. Is it possible to convert an email address that is within Google Workspace to their name? 2. Is it possible to save the document to PDF instead of a editable document?
Thank you for the tutorial, really helpful. DO you know if there is a way to create multiple of the same table but in the same doc instead of doing it in new docs? Thanks!
Thank you so much for the video! I have never coded anything before, and I was able to follow your steps and create a huge time-saver for our school's secretary. I appreciated how you explained everything so clearly - it really helped me understand what I was doing and also helped me find mistakes when the errors popped up. :)
This is really useful! Is there a way to automatically link the new pages you create back to the parent spreadsheet, so that certain columns can be filled in when the sheet for a particular row is modified?
Is there a way to write this code so that if you add more information to the sheet you can rerun it only for those that do not have a link for a google doc? Thank you!!!
Hello! Thanks! Your video helped a lot. I have 1 question! Why decimal coma's becomes decimal dot's after running script? In my sheets i use decimal coma's.
Hi Jeff, I have started my own project (as a way of learning Google apps script), love the power!! I have used your example above except modified it to modify an invoice spreadsheet template instead of a google doc. I am having trouble with an error I just recently started getting - "Exception: The starting row of the range is too small." Would you mind looking through my beginner code to help me out... sure it will be a quick fix for you?!
Hey, thanks for the amazing Content! I got a question, i am trying to change the destination folder to 5 diffrent folders depending on the Text that is in cell 1 - so if cell 1 says "John" then i want the File to be created in the FOlder "Documents John" if the Cell says "Lisa" hen i want the File to be created in the Folder "Documents Lisa". i got 5 Names in Total - so 5 Folders in Total. I guess i need to do it with an "if" statement, but i dont get it to work..
Thank you very much for this! it was very helpful! just one question. Is it possible to add an image to the template from the google sheet? and how would that be??
Hi Jeff- Was able to follow this video and got things working nicely. Once my form is submitted and the Google Doc is created, is there a way to automatically email the DOC out to a list of people I specify? Thanks in advance!
Hi Jeff, Thanks for this video. Super helpful. I have a question. I would also like to pull data from a second sheet on the spreadsheet. I've been working on it over the weekend and still can't seem to figure it out. Would you be able to assist?
Hi, thanks for the tutorial! Very helpful and easy to follow. I have a question: instead of text or dates, I have numbers to transfer from GSheets to GDocs. With your (wonderful) script I get numbers without format. For example I have a number in GSheets formatted as 170,000 and in GDocs it comes out as 170000. Same happens for percentanges (from 25.1% to 0.251) Is there a way to respect the original formatting? Thank you!
Now when I run the script from the spreadsheet file, I get this exception: 'Exception: Document is missing (perhaps it was deleted, or you don't have read access?)' The script cannot get access to the copied document once it was created because of a lack of permissions. Any ideas on how to solve this? Thanks! UPD: If you'd like to have a spreadsheet as your destination document, use `SpreadsheetApp` instead of `DocumentApp` :)
Best code I found to perform this function! Elegant, to the point and handles spreadsheets with hundreds of rows (the known google bug issue notwithstanding). Thank you so much :D
Thanks for the kind words and thanks for watching _ JE
Рік тому
What a great tutorial for someone new to Apps Script like me. I also did the same and made a few customizations in the data table. The problem I encounter here is that the code creates Document files from lines without data. So how to prevent this? Help me.
Рік тому
function onOpen() { const ui = SpreadsheetApp.getUi(); const menu = ui.createMenu('Biên bản'); menu.addItem('Tạo biên bản mới', 'createNewGoogleDocs'); menu.addToUi(); }
function createNewGoogleDocs() { const googleDocTemplate = DriveApp.getFileById('1gV1i9hld0OoL6zZ9Q8NgbCKG0iKncDWS-3WlwRZ9q7U');
Awesome video! So close to what I need! Two questions if you would be so kind... How can I auto populate the column without the auto fill button and how can I email the doc link automatically to the person it should go to?
It's a little bit more complicated, you'd need to use this class to do it: developers.google.com/apps-script/reference/spreadsheet/spreadsheet#createTextFinder(String)
Thanks for the tutorial. It was very informative and easy to follow.... I copied all and followed each and every step as instructed in the video...yet... after executing AutoFillDoc in the Sheet the following pop up appears: "TypeError: Cannot read properties of null (reading 'getDataRange')" Any idea where the culprit is?
Thanks so much for the tutorial, it was really helpful. I have a question; How can I select a different template depending on the value of a cell? For example, if the value is equal to XX, a template is selected, while if the cell is equal to YY, a different one is chosen.
Add an additional if/else statement before you make a copy. Use one template in the first block, then the second template in the second block. There are more advanced design patterns if you really want to get into it, but for one-off scripts, just copy and paste, then change the relevant ids.
@@brandonwilson1600 Don't you also have to swap out the "const googleDocTemplate = DriveApp.getFileById(" line right after the Create new GoogleDoc function? What makes it search among a few different templates?
@@pmont72782 Yes, it would be exactly that. Each branch of the If/elseif/else would have it's own version of that line with a different ID, and potentially different code leading to how to fill out the cells, depending on how complicated the resulting structure ends up being.
Or you could set it up as "const googleDocTemplate1 = DriveApp.getFileById(" "const googleDocTemplate2 = DriveApp.getFileById(" ... or "const googleDocTemplatePurchasing = DriveApp.getFileById(" "const googleDocTemplateInvoicing = DriveApp.getFileById(" ... etc. and then just use the appropriate template file in the appropriate branch.
That's the best tutorial out there. Thank you so much for all the explications, you're a really good teacher. I wish I could give that video 100 likes!
Thanks so much for this easy to follow vid. i did have a question as i was hopeing to add on to this. is there a way to have it create and new sub folder in the folder named one of the cells then save the doc it is creating into that? meaning every time it created a new url and doc it is also creating a folder for that doc to go into? again thanks for the video
Hi Jeff, very well done ... and it helped me a lot. But i have another issue ... ( e.g. an Invoice with header informations and then a table with the invoice items ) In my template the items are in a table ... and this is where the problem starts. How can i fill in a loop item for item in the docs template ( items in a table ) ... All over the net i found no solution ... 😢
Thanks, Jeff, this is a great tutorial - with your clear explanation of something I (as a total novice) don't understand *at all* I was able to make this work for me sheet. The sheet is made automatically from responses to a form, and your method worked a treat. The only thing I've had trouble with is following the other bits of advice I've seen in the comments about images. I have image URLs submitted as part of the form, and I get stuck trying to make these URLs show as images in the generated doc. Did anybody have success with this?
Yes, someone was able to figure that out in the comments. Visit this page and search for 'replaceTextToImage' to see how it was handled: jeffreyeverhart.com/2018/09/17/auto-fill-google-doc-from-google-form-submission/
Hi, great video. One question is there a way to input data from google sheet in a bunch of EXISTING google docs? Basically, I have around 100 google docs (10 pages each). Just one of those pages needs to be changed o a monthly basis.
Great Video! i did have a question. I want to implement this to an inventory / equipment maintenance system. Will this auto update the Google Docs with information when its changed in the spreadsheet? if not, is there a way to do so?
Hi, your tutorial is really great and exactly what I looked for. Unfortunately, a problem appeared after activating the 'forEach' loop. I got the error: rows.forEach is not a function. I will really appreciate if you help me with that. Thank you
Hi Jeff! Thank you for this. I'm looking to import "in-line" text into a Google Doc from a Google Sheet? I think this is really a close way to do it. I'm trying to make a report like this: You webpage got X,XXX visits this month and we posted X,XXX pieces of content. This would pull from a Google Sheet with all that information, but would also be able to tell which month it's in so it would update monthly. Could I use this script to do that or would it need to be different? I don't need to creat new documents, just update the one document from multiple already created Spreadsheets. Thanks for the resource!
Hi Jeff Thanks for the tutorial Is there a way I can prevent regenerating all documents every time I run the generate new form Script and only generate the new document with the recent data entered or even better if I can specify the certain document I intended to have or If possible only edit the previously generated documents and generate the newly added data rows
I'm curious about is whether or not we actually need to use {to create a tag. Could I just use the first and last name? That might sound like a weird question but my goal is to update there document instead of replacing it. Did a lot of reasons why a person might want to do this. In my case I create Google. Invoices that I send out the clients who then have to share that same URL with 20 different people in order to get me paid. It has happened many times wherever create a new document after an update and I would get paid the wrong amount because the most current URL did not make it up the chain of command. From our contacts, here's what I have set up. When I book a client the data comes through form an invoice is created. Upon form submission their data along with the invoice is copied to a second sheet. My thinking is if I update the form response sheet, the data on the second spreadsheet should still match everything on the invoice. I want be able to set the data range on the second sheet as a variable for my tags. If I run my update invoice script, my hope is the script will see the data as the tags on the document we could get by the URL, and then replace those tags with what is currently on the booking for response sheet. To make this easier, we can do one row at a time. I don't need to Loop through the entire. I know I can type in a specific number and save that as a variable in the script, so it would only go through that one row. Is what I'm saying making any sense? Does this sound feasible?
Hi Jeff awesome tutorial. Can you perhaps make a similar video but to save to PDF and perhaps with a ticking box on Google Docs to tick the box if you have a dropdown on your Google Form?
Hi Jeff, this is great. Would you please make a video like this with a google slides template instead of google docs? Everything else would be the same. I have been trying to do this for google slides instead of Google docs and I can’t figure it out.
I am getting this when I try to run: Script function not found: createNewGoogleDocs. I've refreshed and tried to run again but still get this. No error popped up in the script when I ran it so got excited and now got this. Any ideas? Thank you SO much for this tutorial.
Thank you for the incredible tutorial. It was very easy to follow and helped someone like myself, who had never coded with Apps Scripts, to get a sense of how the language works and be able to personalize my script for my intended application. I've already build off of your script to automate the filling of multiple documents at the clinic I work at, which will dramatically decrease the burden on our doctors and nurses, and allow them overall more time to focus on patient care. Thank you for helping us make that difference!
Thanks for watching!
This tutorial really helped my company save time and mistakes on filling out paperwork. The autofill feature we created with this, and his "Adding Custom Menus" video took some tinkering, but we got it to work, and everyone's delighted at this low cost, low maintenance solution. Thank you Jeff!
Thanks for the kind words and thanks for watching!
I just started a role at a new company and docs and sheets are a major part of the workflow. This gives me a great quick way to automate things without standing up a full Python or Node.js application to do it.
Thanks Jeff.
This will come really handy for us.
1. Data collected through google form.
2. Data dumps into spreadsheet
3. Use this script to create a letter for sending out to clients
The UI in Google Sheets is slightly updated from when this was recorded, but even with my rudimentary coding knowledge I was able to modify this to work. THANK YOU, this is amazing.
@Jeff Everhart out of curiosity, is there a way to use template literals to have the scrip generate a new folder, and store the document in that folder?
Update: Yes, there is! I fed the script to ChatGPT and asked if it could modify to generate a new folder. I can share if anyone wants
Oh wow, that's pretty cool
@@moving2fast2 Please do share!
That is actually a very good tutorial!
I first watched a crappy one called "Autofill Google Doc Template from Google Sheets | Google Apps Script" from the channel Outright System... The guy just stole your code, without even giving you credit, and pasted it without any explanation! Some people have no shame and are awful educators, really.
But thank YOU for the great explanation and time you took to actually teach us!
This is just what I need! Hopefully I can execute this on my own template, I don’t really understand any programming language but I’ve surviving by copying codes out of tutorials and browsing the net. Thank you so much for sharing your knowledge!
Awesome! Thanks for watching
Thank you so much for this tutorial! It is so much easier to understand and adapt to different situations when you take the time to explain what every line does instead of just importing a pile of code from some website.
How come this guy only has 2.2k followers? Doing such a great job sharing this type of content so carefully so anybody just stepping in this would be able to understand?
thank you So much man!! God bless you!
This script was FANTASTIC! I used it to create a hundred individual data forms from a Google Sheet with nearly 100 individual data points. Thank you!!
This was my first dive into Google Scripts or any code for the matter. And it was a successful one!
This saved me a lot of hassle and put me on a way of Excel / Sheets skill development and put a lot of ideas into my mind about working with code.
You are truly a special kind of person for doing this, at least in my life! Thank you very much.
Thanks for watching!
This is brilliant! Any chance you can add the script for when there is a choice of templates to pull on depending on a criteria specified in the form????
Thank you for a great tutorial. This is going to save me and my husband so much time with filling out legal documents for our real estate business. I am a complete novice when it comes to coding, but this was very easy to follow and understand. The only thing I had a problem with was an error saying that the document was inaccessible. But, I realized that I had been using a .docx (Microsoft Word) document and that google docs didn’t recognize it within the code, even though it could open the file and edit it. Just thought I’d mention that in case anyone else had the same problem.
is it just me or the 'real estate business' part is tmi
Thank you for the hint about docx, we have tried days to solve this.
Your tutorials are excellent, you do a great job of explaining as you go along. I originally used your prior video, "Auto Fill Google Doc from Google Form Using Google Apps Script," but found on occasion it would fail to generate the doc, without explanation (i.e. someone submits a form, it goes to the spreadsheet, but the doc just doesn't happen.) The method you demo here allowed me to set up a manual workaround for those occurrences.
Amazing video !
Allowed me to create 10 docs for a client that usually takes me 20 minutes each to create.
Thanks so much Jeff 😍
You are incredible. I was trying for so many days. I have no coding knowledge but just a determination to solve a problem we had. Thank you!!
Thank you a million Jeffrey! I had a question. What if an employee has two rows (for example an employee has two different jobs, each with their own separate pay and hours, etc.)? Is there a way to have details from two separate rows populate into a document, separately?
Reply
You just saved myself and a handful of my colleagues hours of work. THANK YOU for this tutorial!!!
Glad I could help!
This is exactly what I was missing in my function..... grabbing the link to the created Doc and posting it back to the spreadsheet. Thanks again.
Awesome, glad part of that was helpful to you! Thanks for watching
Thanks for this Jeff. I want the rows of the sheet to populate sections of a single document, not create multiple documents. Which line of code to I delete or modify so that the loop sends the data of each row to the single document?
Wanted to see if anyone could respond to this awesome question, don’t need to make so many documents.
instead of trying to do that i think it would be easier to just merge all the documents you create
Great video. I have a question though. Your Google app script primarily works for one column and multiple rows in google doc. Can you help us with Google app script where it generates multiple columns and rows table on Google doc using the data that is available on a single row of Google sheet?
They've shuffled some of the buttons around, but this still works like a charm.
Well done, and good show!
thank you! you really put in the effort to explain everything so that beginners like me can understand the reasoning behind each line and therefore customize the script later on.
Thanks for the kind words
This was incredibly easy to follow! Thank you so much!
I have several cells that have formulas that rely on other cells. If the target cells are blank, it returns a "" or blank. This script creates documents for all of these rows. Using your tutorial, I was able to add a line of script that if the first name was blank it moves on!
Hello, Can you let me know if you've found a solution to your problem?
I did!
function criarpdf () {
const ui = SpreadsheetApp.getUi();
const menu = ui.createMenu('Cria um PDF');
menu.addItem('Cria um PDF, e Envia para um E-mail', 'CriarEEnviarPDFPorEmail');
menu.addToUi();
}
function CriarEEnviarPDFPorEmail () {
const googleDocTemplate = DriveApp.getFileById('1Z1rHTPsl0N65oSx7ILrnzDvEhGCmnoMHInAGB0s6Ffk');
const destinationFolder = DriveApp.getFolderById('1GXbtYSVR5i4LYQWnezY84Hih4liWX4nO');
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data');
const rows = sheet.getDataRange().getValues();
rows.forEach(function(row, index){
if (index === 0) return;
if (row[3] || row[4]) return; // verifica se já há um URL na coluna 4 ou 5
const copy = googleDocTemplate.makeCopy(`${row[1]}, ${row[0]} Employee Details`, destinationFolder);
const doc = DocumentApp.openById(copy.getId());
const body = doc.getBody();
const friendlyDate = new Date(row[3]).toLocaleDateString();
// Faz as substituições usando o objeto keyIndexMap
Object.keys(keyIndexMap).forEach(function(key) {
body.replaceText(`{{${key}}}`, row[keyIndexMap[key]]);
});
doc.saveAndClose();
const email = row[2];
const url = doc.getUrl();
sheet.getRange(index + 1, 4).setValue(url);
var pdf = DriveApp.getFileById(doc.getId()).getAs(MimeType.PDF);
GmailApp.sendEmail(email, "New Employee Details Document", "Please find attached your Employee Details Document",
{attachments: [pdf]});
});
}
At this point, I'm honestly more used to your voice on 0.5x speed haha. Again, thanks so much for this tutorial, it has helped my business a lot to automate some of our systems. I'm officially crowning you as the dad of Google Sheets haha!
Thank you SO MUCH!!! It's so hard to find good tutorials on Google App Script.
Hey Jeff,
Thanks so much for this !
Out of interest how would i take a cell that has a URL in it and replace a tag in the doc with the image rather than the URL ?
Thank you for this resource! This may be a silly question - This is my first attempt at exploring apps script or coding. Can I do this for just one row of data at a time? My spreadsheet is form responses and some of them require a template checklist of next steps for the team, but not all. It's constantly collecting responses. I do have a column that records whether or not a template needs to be generated.
I keep getting the error: Exception: The parameters (String) don't match the method signature for DocumentApp.Body.replaceText. Any idea what may need to be fixed? I have everything plugged in as you do in the video.
Thank you for the great tutorial. I was wondering if it is possible to have the filled Docs merge into a single Doc, rather a separate doc for each employee. Thanks
Excellent class, we added an extra menu item and function for that item on the menu. Thank you so much, it was such a pleasure to learning with you.
Thanks so, so much for this. I'm just dipping my toes into coding and wouldn't have been able to do this sort of thing without your helpful, clear instructions and provision of the template! I made some mistakes in my version of it, but because I was able to rewatch your tutorial, I learned not only what I did wrong, but how to identify where in the code the mistake was made.
Awesome, glad this was a helpful resource. Best of luck -JE
This video is the best! you explained it so well. I needed to add a few more pieces to my code. Having gone into this with no idea how to use AppScript did not matter! This video pointed out to me in the right way to ask my questions online and I was able to get everything to work! Thank you Jeff!
Awesome, that is great to hear. Cheers -Jeff
This was so helpful!! Thank you - I created a merge doc weeks ago and went back to your website to find out about formatting (currency)... and found the answer in you FAQ! Massive help - thank you!
You, Are, The, Best! Couple adjustments and it works FLAWLESSLY for my use case!
Great video! simpel and to the point. One question, what if I have a chunk of text and tables in my template, and I want to make it appear or dissappear in the output doc based on a clickbox in the sheets docs. How would I do that? I have a template with descriptions for different services, but I need that segment of text/tables only if the service is procured. So I want to have a list of services in sheets, click on the ones the customer procures.
Absolutely fantastic video, thank you so much! I just have one question. I have hyperlinks in one column of my spreadsheet, how can I put those in the document? I tried doing it just like your tutorial, but it replaces only the text, not its formatting (i.e. hyperlinks). Is there a workaround?
This is amazing!! Thank a million. just one question, how can i have the document URL to be a 'hyperlink' instead of the long url?
Thank you Jeff for the great tutorial. I had one question, is there a way to create an if statement to read a value in a row to see which google doc template the script should use? I started it with a function with if statements having it read the value in row[x] === "PARTICULAR LANGUAGE" then return the value for the googleDocTemplate = DriveApp.getFileById ('FILE ID'). Sorry if this is a bit confusing. I have multiple templates for different employee variables and want to write the code once versus have multiple codes for each template. I want the script to do the work.
Thank you so much. Concise, clear and competent instructions! A great contrast to a lot of other help out here. It's helped me sort out a formatting issue for an online form. What I would really love is to email the resulting doc (form submission output file) as a PDF to myself/my colleague. I have not been able to resolve the variable for the output filename... thanks for any help you are able to give.
You can find an example of that here: jeffreyeverhart.com/2015/01/30/tech-tip-google-forms-confirmation-email-with-attachments/
Thank you so much for taking the time with these tutorials. Very straight to the point and an easy steps. It's really helping me a lot with my business automations! THANK YOU!
Thanks for watching!!!
I have an issue. rows.forEach --> when I try to execute it says Rows is not defined. The data is not being returned as an Array so I cannot use the .forEach. ? Make sense?
Nevermind -- missed the line defining rows. Thank you so much!!
Hi Jeff, amazing video and great teaching skills. I was wondering if instead of creating google docs we are able to create PDFs named with a field and saved them to a google shared drive?
Excellent tutorial for sheets to docs. Do you have a tutorial for sheets to slides? I thought I could replace the "docs" Apps with "slides" Apps but didn't work. This is the first time using Google Apps Script. thanks
Great tutorial and really easy to follow. Helps solve a problem I've been having 🙂
Is there coding that could be used to also automatically share (view only) the resulting doc with someone in domain if their email address was also a field in the sheet?
Jeff, This tutorial video was great! I know nothing about coding, but I followed your video and it worked! I have one big question - in my sheet at the bottom of each column, I have a SUM function. This SUM function row will be moving further down the sheet as I add more content to the sheet. How can I prevent it from reading this row?? Thank you!
You just saved a whole lot of time to lots of people including me, brilliant tutorial!
Amazing tutorial! You made this so simple to follow and understand. This will save me an unbelievable amount of time creating ICAs. Thank you so much.
Thank you for your instructions. They are very well done. Do you have any options for how to output just the date from a cell in the month/day/year format?
Walking through this very slowly thank you! How do you only get a range of the data, instead of the whole sheet?
tried googling this for you and found a stackoverflow article, search this:
differences-between-getrange-getdatarange-and-getactiverange
here's part of the answer:
"
getRange() has multiple implementations.
Sheet.getRange(row, column)
Sheet.getRange(row, column, numRows)
Sheet.getRange(row, column, numRows, numColumns)
Sheet.getRange(a1notation)
"
So you'd have to play around with the getRange parameters in your code, to select a part of the range instead of it all.
Thank you so much for sharing this, and for the accurate explanation. It was super usefull to me 3 years after you originally posted it.
Thanks! :)
This is AMAZING. not only do i understand the what, but I also understand the why. You are a great instructor.
Hi Jeff, thanks for such wholesome content! Id just like to ask for my case, I have a table template in Google doc, and I want to insert a new row automatically once there are 2 products or more, how can I do it, please? Any help will be much appreciated, thanks in advance!
This is such a great tool! I have managed to get this working for a couple of uses however I was wondering a few things:
1. Is it possible to convert an email address that is within Google Workspace to their name?
2. Is it possible to save the document to PDF instead of a editable document?
Thank you for the tutorial, really helpful. DO you know if there is a way to create multiple of the same table but in the same doc instead of doing it in new docs? Thanks!
Thank you so much for the video! I have never coded anything before, and I was able to follow your steps and create a huge time-saver for our school's secretary. I appreciated how you explained everything so clearly - it really helped me understand what I was doing and also helped me find mistakes when the errors popped up. :)
Thanks for the kind words! Glad it helped you out and got you started.
This is really useful! Is there a way to automatically link the new pages you create back to the parent spreadsheet, so that certain columns can be filled in when the sheet for a particular row is modified?
Is there a way to write this code so that if you add more information to the sheet you can rerun it only for those that do not have a link for a google doc? Thank you!!!
Hello! Thanks! Your video helped a lot. I have 1 question! Why decimal coma's becomes decimal dot's after running script? In my sheets i use decimal coma's.
Hi Jeff, I have started my own project (as a way of learning Google apps script), love the power!! I have used your example above except modified it to modify an invoice spreadsheet template instead of a google doc. I am having trouble with an error I just recently started getting - "Exception: The starting row of the range is too small." Would you mind looking through my beginner code to help me out... sure it will be a quick fix for you?!
Hey, thanks for the amazing Content! I got a question, i am trying to change the destination folder to 5 diffrent folders depending on the Text that is in cell 1 - so if cell 1 says "John" then i want the File to be created in the FOlder "Documents John" if the Cell says "Lisa" hen i want the File to be created in the Folder "Documents Lisa". i got 5 Names in Total - so 5 Folders in Total. I guess i need to do it with an "if" statement, but i dont get it to work..
Amazing, thank you so much. Just wondering how I can get the script to read 'all sheets' and create pdf's instead of docs from the data?
sir did u find solution? if yes then please let me know
THANK YOU! But can I have just one file for these? I mean one file with different pages for employees?
Thank you very much for this! it was very helpful! just one question. Is it possible to add an image to the template from the google sheet? and how would that be??
Thank you very much, Jeff. Your video helps a lot. Is there a way to copy 'named range' from sheets to docs?
This absolutely awesome. Thanks for your great tutorial and this is what needed for me.
Hi Jeff- Was able to follow this video and got things working nicely. Once my form is submitted and the Google Doc is created, is there a way to automatically email the DOC out to a list of people I specify? Thanks in advance!
Hi Jeff,
Thanks for this video. Super helpful. I have a question. I would also like to pull data from a second sheet on the spreadsheet. I've been working on it over the weekend and still can't seem to figure it out. Would you be able to assist?
Thanks Jeff, it will help me a lot.
But if I wanted to send this document file to my webmail in a word format? It can be done?
Hi, thanks for the tutorial! Very helpful and easy to follow.
I have a question: instead of text or dates, I have numbers to transfer from GSheets to GDocs. With your (wonderful) script I get numbers without format. For example I have a number in GSheets formatted as 170,000 and in GDocs it comes out as 170000. Same happens for percentanges (from 25.1% to 0.251) Is there a way to respect the original formatting? Thank you!
Now when I run the script from the spreadsheet file, I get this exception:
'Exception: Document is missing (perhaps it was deleted, or you don't have read access?)'
The script cannot get access to the copied document once it was created because of a lack of permissions.
Any ideas on how to solve this?
Thanks!
UPD: If you'd like to have a spreadsheet as your destination document, use `SpreadsheetApp` instead of `DocumentApp` :)
Glad you were able to work through this, and thanks for posting the results for everyone else. Thanks for watching!
You can't goto tools script editor anymore, but you can type script editor in help and when you search it shows apps script editor
Hi! Great tutorial! I have one question is it possible to use this to fill like 3 different templates depending on conditions from sheet?
Hello there, thanks for the amazing tutorial, I just had a question is there something similar for google slides? as in to autogenerate google slides!
Best code I found to perform this function! Elegant, to the point and handles spreadsheets with hundreds of rows (the known google bug issue notwithstanding). Thank you so much :D
Thanks for the kind words and thanks for watching _ JE
What a great tutorial for someone new to Apps Script like me. I also did the same and made a few customizations in the data table. The problem I encounter here is that the code creates Document files from lines without data. So how to prevent this? Help me.
function onOpen() {
const ui = SpreadsheetApp.getUi();
const menu = ui.createMenu('Biên bản');
menu.addItem('Tạo biên bản mới', 'createNewGoogleDocs');
menu.addToUi();
}
function createNewGoogleDocs() {
const googleDocTemplate = DriveApp.getFileById('1gV1i9hld0OoL6zZ9Q8NgbCKG0iKncDWS-3WlwRZ9q7U');
const destinationFolder = DriveApp.getFolderById('1wpscak7AvL9RY68-LUhO8mKl1ZqP_J09')
const sheet = SpreadsheetApp
.getActiveSpreadsheet()
.getSheetByName('BB kiểm tra')
const rows = sheet.getDataRange().getValues();
rows.forEach(function(row, index){
if (index === 0) return;
if (row[15]) return;
const copy = googleDocTemplate.makeCopy(`${row[1]}, ${row[14]}` , destinationFolder)
const doc = DocumentApp.openById(copy.getId())
const body = doc.getBody();
const friendlyDate = new Date(row[14]).toLocaleDateString();
body.replaceText('{{ProjectName}}', row[1]);
body.replaceText('{{Construction}}', row[3]);
body.replaceText('{{Supervision_Consultant}}', row[4]);
body.replaceText('{{StartDay}}', row[5]);
body.replaceText('{{FinishDay}}', row[6]);
body.replaceText('{{Fulltime}}', row[13]);
body.replaceText('{{Check_Day}}', row[14]);
body.replaceText('{{ConstructionPeriod}}', row[7]);
body.replaceText('{{Progress}}', row[8]);
body.replaceText('{{Secure_Traffic}}', row[11]);
body.replaceText('{{Work_Safety}}', row[9]);
body.replaceText('{{Environmental_Sanitation}}', row[10]);
body.replaceText('{{Project_Information_Board}}', row[12]);
doc.saveAndClose();
const url = doc.getUrl();
sheet.getRange(index + 1, 16).setValue(url)
})
}
Jeff, thanks so much for the tutorial. Each step is explained extremely well. I just used it to automate creating invoices for my freelance work.
Great use of the script, best of luck - JE
Awesome video! So close to what I need! Two questions if you would be so kind... How can I auto populate the column without the auto fill button and how can I email the doc link automatically to the person it should go to?
Thanks, Very Helpfull. How ta make the function run Automatic when adding new data in sheet?
This was excellent. Would you happen to know what needs to change in your script if your template is another google sheet and not a google doc?
It's a little bit more complicated, you'd need to use this class to do it: developers.google.com/apps-script/reference/spreadsheet/spreadsheet#createTextFinder(String)
Thanks for the tutorial. It was very informative and easy to follow.... I copied all and followed each and every step as instructed in the video...yet... after executing AutoFillDoc in the Sheet the following pop up appears: "TypeError: Cannot read properties of null (reading 'getDataRange')" Any idea where the culprit is?
Great video and instructions. One of the fields I want to populate is in the footer, is this possible ?
Thanks so much for the tutorial, it was really helpful. I have a question; How can I select a different template depending on the value of a cell? For example, if the value is equal to XX, a template is selected, while if the cell is equal to YY, a different one is chosen.
Add an additional if/else statement before you make a copy. Use one template in the first block, then the second template in the second block. There are more advanced design patterns if you really want to get into it, but for one-off scripts, just copy and paste, then change the relevant ids.
Did you ever figure this out? I'm in the same boat
@@brandonwilson1600 Don't you also have to swap out the "const googleDocTemplate = DriveApp.getFileById(" line right after the Create new GoogleDoc function? What makes it search among a few different templates?
@@pmont72782 Yes, it would be exactly that. Each branch of the If/elseif/else would have it's own version of that line with a different ID, and potentially different code leading to how to fill out the cells, depending on how complicated the resulting structure ends up being.
Or you could set it up as
"const googleDocTemplate1 = DriveApp.getFileById("
"const googleDocTemplate2 = DriveApp.getFileById("
...
or
"const googleDocTemplatePurchasing = DriveApp.getFileById("
"const googleDocTemplateInvoicing = DriveApp.getFileById("
...
etc.
and then just use the appropriate template file in the appropriate branch.
That's the best tutorial out there. Thank you so much for all the explications, you're a really good teacher. I wish I could give that video 100 likes!
This is SUPER DUPER HELPFUL! How can I add an information as a hyperlink from sheets to the document? Thank you
Well done man! Very nice cadence, explanations, even the error was helpful to see.
Thanks so much for this easy to follow vid. i did have a question as i was hopeing to add on to this. is there a way to have it create and new sub folder in the folder named one of the cells then save the doc it is creating into that? meaning every time it created a new url and doc it is also creating a folder for that doc to go into?
again thanks for the video
Hi Jeff, very well done ... and it helped me a lot. But i have another issue ... ( e.g. an Invoice with header informations and then a table with the invoice items )
In my template the items are in a table ... and this is where the problem starts. How can i fill in a loop item for item in the docs template ( items in a table ) ... All over the net i found no solution ... 😢
Thanks, Jeff, this is a great tutorial - with your clear explanation of something I (as a total novice) don't understand *at all* I was able to make this work for me sheet. The sheet is made automatically from responses to a form, and your method worked a treat. The only thing I've had trouble with is following the other bits of advice I've seen in the comments about images. I have image URLs submitted as part of the form, and I get stuck trying to make these URLs show as images in the generated doc. Did anybody have success with this?
Yes, someone was able to figure that out in the comments. Visit this page and search for 'replaceTextToImage' to see how it was handled: jeffreyeverhart.com/2018/09/17/auto-fill-google-doc-from-google-form-submission/
Hi, this is a great video and helped me a lot. I just wonder if I can save this file as pdf by keeping all the rest same? Thanks in advance! 😊
Hi, great video. One question is there a way to input data from google sheet in a bunch of EXISTING google docs?
Basically, I have around 100 google docs (10 pages each). Just one of those pages needs to be changed o a monthly basis.
Hi Jeff, great Video and it has helped me a lot. I would like to hold my data items in columns (index's) rather than rows. Is this possible?
Great Video! i did have a question. I want to implement this to an inventory / equipment maintenance system. Will this auto update the Google Docs with information when its changed in the spreadsheet? if not, is there a way to do so?
Hi, your tutorial is really great and exactly what I looked for. Unfortunately, a problem appeared after activating the 'forEach' loop. I got the error: rows.forEach is not a function. I will really appreciate if you help me with that. Thank you
Hi Jeff! Thank you for this. I'm looking to import "in-line" text into a Google Doc from a Google Sheet? I think this is really a close way to do it. I'm trying to make a report like this: You webpage got X,XXX visits this month and we posted X,XXX pieces of content. This would pull from a Google Sheet with all that information, but would also be able to tell which month it's in so it would update monthly. Could I use this script to do that or would it need to be different? I don't need to creat new documents, just update the one document from multiple already created Spreadsheets. Thanks for the resource!
Hi Jeff
Thanks for the tutorial
Is there a way I can prevent regenerating all documents every time I run the generate new form Script and only generate the new document with the recent data entered
or even better if I can specify the certain document I intended to have or If possible only edit the previously generated documents and generate the newly added data rows
I'm curious about is whether or not we actually need to use {to create a tag. Could I just use the first and last name? That might sound like a weird question but my goal is to update there document instead of replacing it. Did a lot of reasons why a person might want to do this. In my case I create Google. Invoices that I send out the clients who then have to share that same URL with 20 different people in order to get me paid. It has happened many times wherever create a new document after an update and I would get paid the wrong amount because the most current URL did not make it up the chain of command.
From our contacts, here's what I have set up. When I book a client the data comes through form an invoice is created. Upon form submission their data along with the invoice is copied to a second sheet. My thinking is if I update the form response sheet, the data on the second spreadsheet should still match everything on the invoice. I want be able to set the data range on the second sheet as a variable for my tags. If I run my update invoice script, my hope is the script will see the data as the tags on the document we could get by the URL, and then replace those tags with what is currently on the booking for response sheet. To make this easier, we can do one row at a time. I don't need to Loop through the entire. I know I can type in a specific number and save that as a variable in the script, so it would only go through that one row.
Is what I'm saying making any sense? Does this sound feasible?
Hi Jeff awesome tutorial. Can you perhaps make a similar video but to save to PDF and perhaps with a ticking box on Google Docs to tick the box if you have a dropdown on your Google Form?
Hi Jeff, this is great. Would you please make a video like this with a google slides template instead of google docs?
Everything else would be the same. I have been trying to do this for google slides instead of Google docs and I can’t figure it out.
I am getting this when I try to run: Script function not found: createNewGoogleDocs. I've refreshed and tried to run again but still get this. No error popped up in the script when I ran it so got excited and now got this. Any ideas? Thank you SO much for this tutorial.