简体   繁体   English

如何制作一张纸的副本并将其保存到Google表格中的文件夹中

[英]How to make a copy of a single sheet and save it to a folder in google sheets

I'm currently working on a problem I have where I have around 20 different sheets that I'm working with. 我目前正在解决一个问题,我正在处理大约20个不同的工作表。 With each sheet, I've created a button that says "export" that will save the single sheet (if I can figure it out) to a specified folder. 对于每张工作表,我创建了一个显示“导出”的按钮,该按钮会将单张工作表(如果我能弄清楚的话)保存到指定的文件夹。 I then have a script that clears the sheet so that it's new again (That works great!). 然后,我有一个脚本来清除工作表,以便再次使用它(效果很好!)。 I'm using this in our brewery to take the date of beers in tanks and when the tank is empty, the data is then stored for future reference. 我在我们的啤酒厂中使用它来获取罐中啤酒的日期,当罐中的啤酒为空时,数据将被存储以备将来参考。

So, as of now, the code work pretty much as I'd like it to, but it's saving all of the sheets as one file and now only exporting the sheet that I'm currently looking at. 因此,到目前为止,该代码的工作原理与我想要的差不多,但是它将所有工作表保存为一个文件,并且现在仅导出我当前正在查看的工作表。

Any help on this would be greatly appreciated. 任何帮助,将不胜感激。

I've tried a couple different codes and this is as close as I've gotten. 我尝试了几种不同的代码,而这与我所获得的差不多。

function createCopy() {
  var myValue = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("A29").getValue();
  var destinationFolder = DriveApp.getFolderById("<<google drive folder>>");
  DriveApp.getFileById(SpreadsheetApp.getActiveSpreadsheet().getId()).makeCopy(myValue,destinationFolder);
}

If all goes well, it will save a single sheet to my destination folder. 如果一切顺利,它将单张纸保存到我的目标文件夹中。

I don't think there is a way (or rather, I don't know of one) to copy just one sheet out of the spreadsheet, except by creating a new spreadsheet, copying your sheet there and moving that new spreadsheet in your folder. 我认为没有办法(或者说我不知道​​)从电子表格中仅复制一张表格,除非创建一个新的电子表格,将表格复制到该表格中,然后将新的电子表格移动到文件夹中。 Makes your code a bit longer, but I believe this should do the trick: 使您的代码更长一些,但是我相信这应该可以解决问题:

function createCopy() {
  var myValue = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("A29").getValue();
  var destinationFolder = DriveApp.getFolderById("<<google drive folder>>");
  var backupSpreadsheetId = SpreadsheetApp.create(myValue).getId();
  var backupSpreadsheet = SpreadsheetApp.openById(backupSpreadsheetId);
  SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().copyTo(backupSpreadsheet);
  backupSpreadsheet.deleteSheet(backupSpreadsheet.getSheets()[0]);
  var backupFile = DriveApp.getFileById(backupSpreadsheetId)                                                             
  var currentParent = backupFile.getParents().next();
  destinationFolder.addFile(backupFile);
  currentParent.removeFile(backupFile);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 google sheet 复制到 google drive 文件夹中 - Make a copy of google sheet into google drive folder 尝试从 Google 表格中的 URL 将文件的副本保存到特定的 Google Drive 文件夹 - Trying to save a copy of a file to specific Google Drive folder, from URLs in a Google Sheet Google Sheets 在将其合并到另一个工作表时保存工作表的样式 - Google Sheets save the style of sheet while merging it to another sheet 如何根据sheet1中提到的范围复制谷歌表格中的行数 - How to copy rage of rows in google sheets according to the range mentioned in sheet1 如何使用 Google Sheets Macros 从一张工作表复制值并将它们粘贴到另一张工作表中? - How to copy values from one sheet and paste them into another using Google Sheets Macros? 如果值存在于工作表 1 和工作表 2 中,则复制行并将其粘贴到工作表 3。Google 表格。 Google Apps 脚本 - Copy row if value exists in both sheet 1 and sheet 2 and paste it to sheet 3. Google Sheets. Google Apps Script 使用 Google Apps 脚本,如何替换 Google 表格模板中的文本以制作新表格? - Using Google Apps Script, how can I replace text in a Google Sheets template to make a new Sheet? 谷歌表格 - 宏不会将图表的格式复制到另一个表格 - Google Sheets - Macro doesn´t copy the format of a Chart to another Sheet 通过for循环谷歌表格脚本将行复制到另一张表格 - Copy row to another sheet via for loop google sheets script Google Sheets API:从公共工作表中读取单个单元格值 - Google Sheets API: Read single cell value from public sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM