我正在尝试使用Google脚本更改多个Google工作表中Google工作表单元格的值。
我有一个文件夹,每个文件夹有80个子文件夹。在每个子文件夹中,都有一个标题为“时间管理代理视图-nameOfAgent”的Google表格。我想将每个工作表[1]中的单元格B4的值设置为新值。
我已经尝试过了,但不起作用。当我尝试登录agentSheet时,结果显示为blankA,这可能从代码中可以明显看出来,我是一个非常新的人,并且未经培训;)谢谢您的帮助。
Filip
var regex = "'Time Management Agent View' + /.*/"
var agentsFolderId = 'Folder_ID';
var folders = DriveApp.getFolderById(agentsFolderId).getFolders();
while (folders.hasNext()) {
var agentFolder = folders.next();
var allAgentsSheets = agentFolder.getFilesByName(regex);
Logger.log(agentFolder);
Logger.log(allAgentsSheets);
while (allAgentsSheets.hasNext()){
var agentSheet = allAgentsSheets.next();
Logger.log(agentSheet);
SpreadsheetApp.setActiveSpreadsheet(agentSheet);
var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet()
SpreadsheetApp.setActiveSheet(activeSpreadsheet.getSheets()[1]);
var activeSheet = SpreadsheetApp.getActiveSheet()
SpreadsheetApp.setActiveRange(activeSheet.getRange(2, 4))
var cellToChange = SpreadsheetApp.getActiveRange()
cellToChange.setValue('Test')
}}
}
我知道了!
var str = 'Time Management Agent View'
var regex = /.*/
var agentsFolderId = 'Folder_ID';
var folders = DriveApp.getFolderById(agentsFolderId).getFolders();
while (folders.hasNext()) {
var agentFolder = folders.next();
var allAgentsSheets = agentFolder.searchFiles('title contains "Time Management Agent View"');
Logger.log(agentFolder);
Logger.log(allAgentsSheets);
while (allAgentsSheets.hasNext()){
var agentSheet = allAgentsSheets.next().getId();
SpreadsheetApp.setActiveSpreadsheet(SpreadsheetApp.openById(agentSheet));
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[1];
var cell = sheet.getRange("B4");
cell.setFormula('New_Formula');
var cellContent = cell.getValue();