Google Apps Script Code in Video Below: function createDocument() {
var ui = SpreadsheetApp.getUi(); var fileName = ui.prompt("File Name"); var reportHeader = ui.prompt("Report Header");
var ss= SpreadsheetApp.getActiveSpreadsheet(); var dataSheet = ss.getSheetByName('Data'); var dataRange = dataSheet.getDataRange(); var dataValues = dataRange.getValues();
var destination_id = ''; // ID OF GOOGLE DRIVE DIRECTORY; var destination = DriveApp.getFolderById(destination_id);
var doc = DocumentApp.create(fileName.getResponseText()); var docID = doc.getId(); var file = DriveApp.getFileById(docID); file.moveTo(destination);
var body = doc.getBody(); body.insertParagraph(0, reportHeader.getResponseText()) .setHeading(DocumentApp.ParagraphHeading.HEADING1); table = body.appendTable(dataValues);
var tableHeader = table.getRow(0); tableHeader.editAsText().setBold(true).setForegroundColor('#ffffff'); var getCells = tableHeader.getNumCells();
for(var i = 0; i < getCells; i++) { tableHeader.getCell(i).setBackgroundColor('#BBB9B9'); } } function addMenu() { var menu = SpreadsheetApp.getUi().createMenu('Custom'); menu.addItem('Create Doc', 'createDocument'); menu.addToUi(); } function onOpen(e) { addMenu(); }
What I want to know is If you have knowledge of how to insert a table (or part of it) in a specific location of the ready-made docs document (Ex: in the middle of a ready-made mail merge template)... ..... Just like we do with the function ...replaceText("{NAME}", name)..... but instead of the variable "name", be a table........ your example is nice, but it just inserts the table at the end of the document and doesn't capture values from the worksheet. You can do it? thank you for your attention to my proposed challenge
I want to create tables on a google doc, from a sheet filled from a form, but I need new tables at the beginning of the doc, so last an old tables move down. Do you have a video like this? Thank you for you videos and the code! Help me a lot.
Your videos is great. When can we expect more videos of app script with basic to advance and bases on real life project. which we can use in our work (office, school) etc. hoping to hear from soon.
How do you do this but as a pdf and add a link to the pdf in the Google sheet itself. Essentially, how do you create an a script that acts like the add on autocrat
Can you explain how to get data from Google sheet and display it in table as html page? with out any buttons just table with all the data from Google sheet and if I update by adding more column or rows it will update and get data with every time you refresh the page
@@CodeWithCurt I have seen this before and the result I want did not appear, as I explained earlier. I would like you to explain your method much better and your way of communicating the information is excellent.
Curt, how would you code to immediately open the created document in a new browser tab rather than having to navigate to it? I'm thinking DocumentApp.openById(), but not sure how to provide the string of the docID.
Google Apps Script Code in Video Below:
function createDocument() {
var ui = SpreadsheetApp.getUi();
var fileName = ui.prompt("File Name");
var reportHeader = ui.prompt("Report Header");
var ss= SpreadsheetApp.getActiveSpreadsheet();
var dataSheet = ss.getSheetByName('Data');
var dataRange = dataSheet.getDataRange();
var dataValues = dataRange.getValues();
var destination_id = ''; // ID OF GOOGLE DRIVE DIRECTORY;
var destination = DriveApp.getFolderById(destination_id);
var doc = DocumentApp.create(fileName.getResponseText());
var docID = doc.getId();
var file = DriveApp.getFileById(docID);
file.moveTo(destination);
var body = doc.getBody();
body.insertParagraph(0, reportHeader.getResponseText())
.setHeading(DocumentApp.ParagraphHeading.HEADING1);
table = body.appendTable(dataValues);
var tableHeader = table.getRow(0);
tableHeader.editAsText().setBold(true).setForegroundColor('#ffffff');
var getCells = tableHeader.getNumCells();
for(var i = 0; i < getCells; i++)
{
tableHeader.getCell(i).setBackgroundColor('#BBB9B9');
}
}
function addMenu()
{
var menu = SpreadsheetApp.getUi().createMenu('Custom');
menu.addItem('Create Doc', 'createDocument');
menu.addToUi();
}
function onOpen(e)
{
addMenu();
}
What I want to know is If you have knowledge of how to insert a table (or part of it) in a specific location of the ready-made docs document (Ex: in the middle of a ready-made mail merge template)... ..... Just like we do with the function ...replaceText("{NAME}", name)..... but instead of the variable "name", be a table........ your example is nice, but it just inserts the table at the end of the document and doesn't capture values from the worksheet. You can do it? thank you for your attention to my proposed challenge
I want to create tables on a google doc, from a sheet filled from a form, but I need new tables at the beginning of the doc, so last an old tables move down. Do you have a video like this?
Thank you for you videos and the code! Help me a lot.
Your videos is great. When can we expect more videos of app script with basic to advance and bases on real life project. which we can use in our work (office, school) etc. hoping to hear from soon.
Very nice ! Thank you so much!
I want to combine Google Form, Sheets and Docs into a single Google app script Web app
Hi, is it possible to format text in created google doc in table for example in first column align text to right ?
How do you do this but as a pdf and add a link to the pdf in the Google sheet itself. Essentially, how do you create an a script that acts like the add on autocrat
Superb
what if i only want to print cell no.2 and 4?? what will be the modification?
Can you explain how to get data from Google sheet and display it in table as html page?
with out any buttons just table with all the data from Google sheet and if I update by adding more column or rows it will update and get data with every time you refresh the page
Here is the closest video I got that does pretty close of what your asking.
ua-cam.com/video/17A2jTkeMkU/v-deo.html
@@CodeWithCurt I have seen this before and the result I want did not appear, as I explained earlier. I would like you to explain your method much better and your way of communicating the information is excellent.
Hi
Curt, how would you code to immediately open the created document in a new browser tab rather than having to navigate to it? I'm thinking DocumentApp.openById(), but not sure how to provide the string of the docID.
Is it possible to add hyperlink from google sheet to google doc?
Awesome video.
Thanks