首页 > 解决方案 > 编程以通过在工作表中选择某人的姓名将 Google 工作表添加到某人的云端硬盘

问题描述

当我从我是销售代表的人员列表中选择时,我正在尝试创建一个工作系统,并在副本上填写表格。

只是看看是否还有一种方法,当我选择我的名字时,它也会将该表添加到我自己的驱动器中。

标签: google-apps-script

解决方案


你不是很清楚你想要什么,但这种脚本可能是你要找的。如果没有,对不起。

function saveSelected() {
  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('Employee List');
  var data=sh.getRange(sh.getActiveCell().getRow(),1,1,sh.getLastColumn()).getValues()[0];
  var sObj={name:data[0],ssId:data[1],driveId:data[2]};
  var folder=DriveApp.getFolderById(sObj.driveId);
  var file=DriveApp.getFileById(sObj.ssId);
  file.makeCopy(folder);
}

function loadSideBarButton() {
  var userInterface=HtmlService.createHtmlOutput('<input type="button" value="Save Selected Row" onClick="google.script.run.saveSelected()" />');
  SpreadsheetApp.getUi().showSidebar(userInterface);
}

function onOpen() {
  loadSideBarButton();//When you click this button saveSelected will be called and it will save the spreadsheet for the employee that you have selected with your cursor.  You just have to have selected the correct row.
}

上述脚本适用于以下数据结构。

在此处输入图像描述

当然,您必须获得对员工文件夹的完全访问权限。


推荐阅读