Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72358

Google Script to Fill out HTML Form

$
0
0

I have created a script in google scripts, to take a spreadsheet and fill out multiple google docs successfully. I am trying to apply this logic to filling out an HTML form, basically, we need user-generated info (in our google sheet) to fill out an HTML form on a web page.

QUESTION: How would I get the following function to not only open but write in the data?

This is where I am at (just using an example webpage):

function testNew(){
  var js = " \
    <script> \
      window.open('https://colorlib.com/etc/cf/ContactFrom_v1/index.html', '_blank', 'width=800, height=600'); \
      google.script.host.close(); \
    </script> \
  ";
  var html = HtmlService.createHtmlOutput(js)
    .setHeight(10)
    .setWidth(100);
  SpreadsheetApp.getUi().showModalDialog(html, 'Now loading.'); // If you use this on Spreadsheet
//  DocumentApp.getUi().showModalDialog(html, 'Now loading.'); //  If you use this on Document
//  SlidesApp.getUi().showModalDialog(html, 'Now loading.'); //  If you use this on Slides
} 

This is an example of what I did with the google docs, trying to replicate informs:

function myFunction() {
      var data = Sheets.Spreadsheets.Values.get('google sheet ID HERE', 'A2:R300');
      // google doc template id, already got deal memo
      var templateId = 'google doc ID HERE';
      // loop through the values "i" is looping the rows, "#" is the column example: 0=a,1=b   
      for (var i = 0; i < data.values.length; i++) {
        var date = data.values[i][0];
        var email = data.values[i][1];
        // grab the google doc template, create a copy, and generate the new id
        var documentId = DriveApp.getFileById(templateId).makeCopy().getId();
        // change the name of the new file
        DriveApp.getFileById(documentId).setName(companyName+ '-' + projectName+ '-' + 'Insurance Report');
        // get the document body as a variable
        var body = DocumentApp.openById(documentId).getBody();
        // replace values with google sheet data
        body.replaceText('##Date##', date);
        body.replaceText('##Email##', email);

Thank you for your help!


Viewing all articles
Browse latest Browse all 72358

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>