简体   繁体   English

将 google sheet 复制到 google drive 文件夹中

[英]Make a copy of google sheet into google drive folder

I have two Spreadsheets.我有两个电子表格。 The first spreadsheet contains my raw data that indicates the employee # and name of employees.第一个电子表格包含我的原始数据,表明员工编号和员工姓名。 The second spreadsheet is the spreadsheet I want to copy into a google drive folder.第二个电子表格是我要复制到谷歌驱动器文件夹中的电子表格。 I want to update the specific fields on the 2nd spreadsheet based on the employee number and employee name from the 1st spreadsheet.我想根据第一个电子表格中的员工编号和员工姓名更新第二个电子表格上的特定字段。 Everytime it updates the cells in the second spreadsheet, it will create copy of the 2nd spreadsheet into google drive folder.每次更新第二个电子表格中的单元格时,它都会将第二个电子表格的副本创建到谷歌驱动器文件夹中。

However, it keeps on setting just one value inside the replicated spreadsheets.但是,它继续在复制的电子表格中只设置一个值。 It doesn't loop the employee names and employee numbers from the 1st spreadsheet.它不会循环第一个电子表格中的员工姓名和员工编号。

My code is already replicating the 2nd spreadsheet.我的代码已经在复制第二个电子表格。 It's just the values aren't updating.只是价值观没有更新。

 function replicateCards() {
  var ss = SpreadsheetApp.openById('xxxxxxxx');
  var copyCard = SpreadsheetApp.openById('zzzzzzzzz');
  var getID = DriveApp.getFileById(copyCard.getId())
  var card = copyCard.getSheetByName("Card");
  var mastersheet = ss.getSheetByName("Mastersheet");
  var getLastRow = mastersheet.getLastRow();
  var destinationFolder = DriveApp.getFolderById('yyyyyyyyyy');
  ;
  var changeColorToGrayList = card.getRangeList(['C7', 'E7', 'G7', 'I7', 'K7', 'M7', 'O7', 'Q7',
                                                 'C9', 'E9', 'G9', 'I9', 'K9', 'M9', 'O9', 'Q9',
                                                 'C11', 'E11', 'G11', 'I11', 'K11', 'M11', 'O11', 'Q11']);
  var setValueToZero = card.getRangeList(['C8', 'E8', 'G8', 'I8', 'K8', 'M8', 'O8', 'Q8',
                                          'C10', 'E10', 'G10', 'I10', 'K10', 'M10', 'O10', 'Q10',
                                          'C12', 'E12', 'G12', 'I12', 'K12', 'M12', 'O12', 'Q12']);

  for (i = 1; i < getLastRow; i++) {

    var employeeNumber = mastersheet.getRange(i + 1, 1).getValue();
    var employeeName = mastersheet.getRange(i + 1, 2).getValue();
    card.getRange("C3").setValue(employeeName);
    card.getRange("H3").setValue(employeeNumber);
    card.setActiveRangeList(changeColorToGrayList).setBackground("gray");
    card.setActiveRangeList(setValueToZero).setValue(0);
    //    var getID = DriveApp.getFileById(card).getId(); 
    getID.makeCopy(employeeNumber + " High Flyer Card", destinationFolder);
  }
}

I expect the output of getID.makeCopy(employeeNumber + " High Flyer Card", destinationFolder);我期望getID.makeCopy(employeeNumber + " High Flyer Card", destinationFolder); contains different employee # and employee names, not just one value inside the google folder.包含不同的员工编号和员工姓名,而不仅仅是 google 文件夹中的一个值。

Your code should work as intended, unless a bulky file makes the code overlap.您的代码应该按预期工作,除非一个庞大的文件使代码重叠。

If so, implementation of flush() will make your code run sequentially, see here for a detailed explanation.如果是这样, flush()的实现将使您的代码按顺序运行,请参阅此处了解详细说明。

In your case, modifying the for loop to在您的情况下,将 for 循环修改为

  for (i = 1; i < getLastRow; i++) {
    var employeeNumber = mastersheet.getRange(i + 1, 1).getValue();
    var employeeName = mastersheet.getRange(i + 1, 2).getValue();
    card.getRange("C3").setValue(employeeName);
    card.getRange("H3").setValue(employeeNumber);
    card.setActiveRangeList(changeColorToGrayList).setBackground("gray");
    card.setActiveRangeList(setValueToZero).setValue(0);
    getID.makeCopy(employeeNumber + " High Flyer Card", destinationFolder);
    SpreadsheetApp.flush();  
  }

should solve the issue.应该解决问题。

暂无
暂无

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

相关问题 尝试从 Google 表格中的 URL 将文件的副本保存到特定的 Google Drive 文件夹 - Trying to save a copy of a file to specific Google Drive folder, from URLs in a Google Sheet 如何制作一张纸的副本并将其保存到Google表格中的文件夹中 - How to make a copy of a single sheet and save it to a folder in google sheets 通过Drive API自动执行Google表格操作(制作副本,Google App脚本,触发器) - Automating Google Sheet actions (Make a copy, Google App Script, Triggers) via Drive API 创建Google表格并将其上传到Google云端硬盘上的特定文件夹中 - Create and upload a Google Sheet into a particular Folder on Google Drive 将Google云端硬盘文件夹中的文件和网址列表放入表格中 - Getting a list of file and url in a Google Drive folder into a sheet 尝试将我的 google 工作表以 pdf 格式保存到我的驱动器文件夹时出现问题 - Problem trying to save my google sheet as a pdf to my drive folder 如何从 Google Drive 复制文件夹以使用 JS 在 Google Drive 中创建新文件夹 - How to copy a folder from Google Drive to create a new folder in Google drive using JS 如何在Google SpreadSheet上列出Google云端硬盘文件夹中所有文件的列表 - How to Make a list on Google SpreadSheet of all files in a Google Drive folder 如何在谷歌驱动器 api 中复制文件夹? - How I can copy folder in google drive api? 在 Google 云端硬盘中创建副本后如何自动打开 Google 表格 - How do I automatically open a google sheet after creating a copy in Google Drive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM