google-apps-script

HTMLService forms and responses

大城市里の小女人 提交于 2021-01-28 12:20:19
问题 New to Google scripts. I cannot for the life of me get a Google script for forms working. The documentation is not helpful and I could not find any complete examples. In sheets, I went to the script section. I created a basic "hello world" html. I added a function useMyForm, that will call on the script that has the form in it. After submit I cannot get the form to call the other script that has onFormSubmit. Can someone write me a form with one entry and a call to the function that will

Utilities.formatDate returning wrong week number

≯℡__Kan透↙ 提交于 2021-01-28 12:12:33
问题 In Google Script I have the following code: var myDate = new Date(sheet.getRange(3,1).getValue()); var year = Utilities.formatDate(myDate, "Europe/Amsterdam", 'dd-MM-yyyy'); var weekyear = Utilities.formatDate(myDate, "Europe/Amsterdam", 'dd-MM-YYYY'); var week = Utilities.formatDate(myDate, "Europe/Amsterdam", 'w'); When I insert 30-12-2015 as date, the result will be. // year: 30-12-2015 // weekyear: 30-12-201**6** // week: 1 In my local timezone, it should be week number 53. Not 1. If I

What is the most efficient way to convert a .XLS to Google Sheets in App Script?

非 Y 不嫁゛ 提交于 2021-01-28 11:54:31
问题 I download a .XLS file automatically to a Google drive weekly. I would like to automatically convert the latest downloaded .XLS file every week to Google sheets format. Thus go to specific Google drive folder. Find the latest or unconverted .XLS file. Convert to Google sheets format and save in the same folder. 回答1: You want to convert one .xls file to Google Spreadsheet. The .xls file has 60 kBytes in the file size. The .xls file is put in the specific folder. You want to put the converted

Adding/updating a Google Contact's photo

故事扮演 提交于 2021-01-28 11:38:48
问题 I am trying to update a Google Contacts contact's photo via URL using Google Apps Script. The below is my attempt. function addContactPhoto (blob) { var image = UrlFetchApp.fetch("http://www.example.com/joe_bloggs.png"); var options = { 'method' : 'put', 'contentType': 'image/png', 'payload' : image.getBlob() }; UrlFetchApp.fetch('https://www.google.com/m8/feeds/photos/media/{userEmail}/{contactID}', options); } I was trying to follow the instructions for the Google Contacts API by sending a

Can I randomize items in MultipleChoiceItem?

微笑、不失礼 提交于 2021-01-28 11:32:21
问题 I'm new to GoogleAppsScript and now making quizzes in google form and spreadsheet by using GAS. I want to shuffle items in a MultipleChoiceItem when the google form is reloaded. A part of my current scirpt, slightly modified form this code, is presented below. //vars from spreadsheet var form = FormApp.openById(id); var ss = SpreadsheetApp.openById(question_bank_ID); var text = sheet.getSheetValues(questions[i]+1, 2, 1, 1)[0][0]; var options = sheet.getSheetValues(questions[i]+1, 5, 1, 5)[0];

google.script.run not working on Chrome Browser for some users

六眼飞鱼酱① 提交于 2021-01-28 11:12:07
问题 Google Sheets Add-on is erroring on Chrome when running a google.script.run.myFunction(). It runs correctly on Safari and Firefox and an exact copy of the project on another google user account also runs correctly. Console error message just says uncaught as per the following screenshot: No error is caught by adding .withFailureHandler() and the execution logs don't show the google.script.run as being run 回答1: Issue is as described here We're sorry, a server error occurred while reading from

How do I isolate Drive file ID from URL using regex?

白昼怎懂夜的黑 提交于 2021-01-28 11:10:00
问题 I am trying to get the file name for a file I only have the Google Drive URL for. I am currently using a Google Sheets regexextract function to extract the file ID from the URL, and then using the script to find the file based on the ID, but would prefer to do the regex within the script. I've looked through various posts on here to try to figure it out with no luck. Hopefully someone can spell out what I have done wrong in trying to incorporate the regex. var sheet = SpreadsheetApp.getActive

How do I isolate Drive file ID from URL using regex?

巧了我就是萌 提交于 2021-01-28 11:03:31
问题 I am trying to get the file name for a file I only have the Google Drive URL for. I am currently using a Google Sheets regexextract function to extract the file ID from the URL, and then using the script to find the file based on the ID, but would prefer to do the regex within the script. I've looked through various posts on here to try to figure it out with no luck. Hopefully someone can spell out what I have done wrong in trying to incorporate the regex. var sheet = SpreadsheetApp.getActive

Download Folder as Zip Google Drive API

眉间皱痕 提交于 2021-01-28 10:52:58
问题 I currently have a Google App Script in Google Sheet that gives me the URL of a folder, which I can then use to download. Though it is an extra step I would like to remove, and get the URL of the zipped content directly. Here's my code (google app script): function downloadSelectedScripts() { // ... var scriptFiles = getScriptFiles(scriptFileNames) var tempFolder = copyFilesToTempFolder(scriptFiles) Browser.msgBox(tempFolder.getUrl()) } function copyFilesToTempFolder(files) { var tempFolder =

How do i change/update validation of question (item) in google form with apps scripts

心不动则不痛 提交于 2021-01-28 10:51:53
问题 I have already try to update text validation for my class with google apps scripts but it say "textItem.setValidation is not a function". Please help me function setPass() { var form = FormApp.openById('Google Form ID'); var textItem = form.getItemById(Question ID); var textValidation = FormApp.createTextValidation() .requireNumberEqualTo(22111) .build(); textItem.setValidation(textValidation) 回答1: You are very close to update the question, you only need to add the method .asTextItem() after