如何使用Google Script将电子表格复制到GDrive上的特定文件夹中,而无需复制关联的表单和脚本

我创build了一个表单,将条目logging到Google表单中。 每天一次,我希望将电子表格作为附件通过电子邮件发送给我们的技术人员。 同时,我想在特定的文件夹中制作电子表格的副本,作为“logging”。 我使用下面的代码

function sendEmail() { var oauthConfig = UrlFetchApp.addOAuthService("google"); oauthConfig.setAccessTokenUrl("url"); oauthConfig.setRequestTokenUrl("url"); oauthConfig.setAuthorizationUrl("url"); oauthConfig.setConsumerKey("anonymous"); oauthConfig.setConsumerSecret("anonymous"); var requestData = {"method": "GET", "oAuthServiceName": "google", "oAuthUseToken": "always"}; var url = "url"; var result = UrlFetchApp.fetch(url , requestData); var contents = result.getContent(); var cur_date = Utilities.formatDate(new Date(), "GMT+1", "yyyy/MM/dd") MailApp.sendEmail("bubu@hotmail.com","test" ,"test", {attachments:[{fileName:cur_date + "_Orders.html", content:contents, mimeType:"application/html"}]}); var spreadsheet = DriveApp.getFileById("ID") spreadsheet.makeCopy(cur_date + "_Orders", DriveApp.getFoldersByName("Orders").next()); } 

我遇到的问题是,当“旧”电子表格被复制到新文件夹中时,显然关联的脚本也被复制并链接到电子表格的表单副本。 有没有办法只复制电子表格(也就是单元格中的数据),而没有附加“装饰”。

干杯,尼古拉

我从来没有想过这个问题会发生(复制相关的表格,呃!),我还没有试图确认。 但是由于您只需要这些值,我认为将电子表格内容复制到新的电子表格可能更容易。

 //replacing your last two lines of code var spreadsheet = SpreadsheetApp.openById("ID"); //this assumes you want the values only of the first sheet //and that you don't care about formatting or sheets names, etc //but you have more options here if this is not desired var values = spreadsheet.getSheets()[0].getDataRange().getValues(); var copy = SpreadsheetApp.create(cur_date + "_Orders"); copy.getSheets()[0].getRange(1,1,values.length,values[0].length).setValues(values); var copyAsFile = DriveApp.getFileById(copy.getId()); //I'd recommend using the folder ID instead DriveApp.getFoldersByName("Orders").next().addFile(copyAsFile); DriveApp.removeFile(copyAsFile); //remove from your Drive root folder