小编Joh*_*ith的帖子

在创建命名文件夹之前检查它是否存在

我试图将Google云端硬盘中的特定文件插入到文件夹中.我还想检查是否有名称的文件夹'testFolder':如果是,则将文件插入到现有文件夹,否则创建一个名为'testFolder'.

这是我到目前为止所提出的,但它总是创建一个名为的新文件夹'testFolder'(因此用户有10个文件夹'testFolder'现在命名- 它不会重复使用第一个文件夹).

var copyId = /* the id of the file to copy */;
function InsertFileToFolder() {
  var file = DriveApp.getFileById(copyId);      
  var folder;
  if (folderExists() == true){                        
    folder = DriveApp.getFolder("testFolder"); //<-- No such thing in GAS i think?
  } else {
    folder = DriveApp.createFolder("testFolder");
  }
  folder.addFile(file);
}

//Check whether folder exists or not
function folderExists() {
  var folders = DriveApp.getFolders();
  var flag = false;  
  for(var i = 0; i < folders.length; …
Run Code Online (Sandbox Code Playgroud)

google-apps-script google-drive-api

4
推荐指数
1
解决办法
2928
查看次数

获取当前的月度Google Apps脚本(很多IF语句)

我做了一个脚本,打印出Logger中的当前月份.我认为这可以通过Arrays以更好的方式完成.

这是我到目前为止:

function myFunction() {

var date = new Date();
var mt = date.getMonth();
var currentD     

  if  (mt === 0) {
   currentD = "JAN (qty)";
  }if (mt === 1) {
   currentD = "FEB (qty)";
  }if (mt === 2) {
   currentD = "MAR (qty)";
  }if (mt === 3) {
   currentD = "APR (qty)";
  }if (mt === 4) {
   currentD = "MAJ (qty)";
  }if (mt === 5) {
   currentD = "JUNI (qty)";   
  }if (mt === 6) { 
   currentD = "JULY (qty)"; 
  }if …
Run Code Online (Sandbox Code Playgroud)

javascript google-apps-script

3
推荐指数
3
解决办法
9405
查看次数

在Google日历中更改事件的颜色

我正在尝试使用Google Apps脚本中的高级日历服务来更改日历中特定事件的colorId.

到目前为止,我已经能够列出获得事件和我喜欢的事件.所以我有活动的ID.

function getSpecificEvent(){
  var calendarId = 'primary';
  var eventId = '7h2tbvns2oo4r5gku6ghjfjclk';
  var calEvent = Calendar.Events.get(calendarId, eventId);
  Logger.log(calEvent);
}
Run Code Online (Sandbox Code Playgroud)

这是我在编辑colorID时尝试的,我使用补丁:

function setEventColor(){
  var calendarId = 'primary';
  var eventId = '7h2tbvns2oo4r5gku6ghjfjclk';
   Calendar.Events.patch(calendarId, eventId).colorId('11');
}
Run Code Online (Sandbox Code Playgroud)

但后来我得到这个错误: 在此输入图像描述

在这种情况下,第33行是这一行:

   Calendar.Events.patch(calendarId, eventId).colorId
Run Code Online (Sandbox Code Playgroud)

javascript google-calendar-api google-apps-script

3
推荐指数
1
解决办法
1505
查看次数