Here we read the document via the Google app script and then send the same data to email.
Lets suppose we have a Resume Template, First we store the template link in the Google Sheet.
![](https://techfixxo.com/wp-content/uploads/2024/02/Screenshot-2024-02-06-at-9.16.45-PM-1024x553.png)
![](https://techfixxo.com/wp-content/uploads/2024/02/Screenshot-2024-02-06-at-9.17.35-PM-1024x553.png)
To access the Doc, we will write a function in Google App Script. I have included the code below.
function read_google_docs(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('DocLink');
var doc_url = sheet.getRange('B1').getValues();
var get_doc = DocumentApp.openByUrl(doc_url);
var body = get_doc.getBody().getText();
Logger.log(body);
}
In the code, we first get the sheet and the Doc URL, and then open the document via DocumentApp.
DocumentApp.openByUrl() : Opens and returns the document with the specified URL.
getBody() : Retrieves the active document’s Body.
We get the text of the body.
![](https://techfixxo.com/wp-content/uploads/2024/02/Screenshot-2024-02-06-at-9.47.28-PM-1024x513.png)
Now that we have the body text, we will send it to an email. Below you will find the code needed to send the body text.
GmailApp.sendEmail('[email protected]','Test Subject',body);
Final Code is.
function read_google_docs(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('DocLink');
var doc_url = sheet.getRange('B1').getValues();
var get_doc = DocumentApp.openByUrl(doc_url);
var body = get_doc.getBody().getText();
GmailApp.sendEmail('[email protected]','Test Subject',body);
}
![](https://techfixxo.com/wp-content/uploads/2024/02/Screenshot-2024-02-06-at-9.59.42-PM-1024x551.png)
Now we will create a new Document via Google App Script.
We will begin by getting the text of the body, then we will create a new document, and lastly, we will set the text of the body on that document. The following is the code to create a new document using the Google app script that can be found below.
function create_google_docs(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('DocLink');
var doc_url = sheet.getRange('B1').getValues();
var get_doc = DocumentApp.openByUrl(doc_url);
var body = get_doc.getBody().getText();
var name = 'Ashish';
var new_d = DocumentApp.create(name);
new_d.getBody().setText(body);
sheet.getRange('B3').setValue(new_d.getUrl());
}
![](https://techfixxo.com/wp-content/uploads/2024/02/Screenshot-2024-02-06-at-10.26.54-PM-1024x555.png)
Leave a Reply