
[英]Copy row if value exists in both sheet 1 and sheet 2 and paste it to sheet 3. Google Sheets. Google Apps Script
[英]Wildcard expression when searching for sheet name in google sheets. Google App Script
尝试在导入的文件夹中搜索某些 Google 表格时出现问题。 导入的每个 Google 表格都有一个常规名称和唯一 ID。 例如:手动导出(1024508324)
我创建了一个脚本,它将文件夹中的所有谷歌工作表导入到一个主谷歌工作表中。 以下: '''
function getdata() {
//declare multiple variables in one statement - Initial value will
//be undefined
var destinationSpreadsheet,destinationSS_ID,destsheet,destrange,file,files,
sourcerange,sourceSS,sourcesheet,srcSheetName,sourcevalues;
var pattern = /.Manual./;
srcSheetName = (pattern)
destinationSS_ID = "1DmG5DuWmBqaImUuVvXrhH6mRRozsv7ksjYoFLbEhVGY";
files = DriveApp.getFolderById("13Z0RSeWnzW9mbm1wnTOEQrkzxUFCdCZF").getFiles();
destinationSpreadsheet = SpreadsheetApp.openById(destinationSS_ID);
destsheet = destinationSpreadsheet.getSheetByName('Master');
while (files.hasNext()) {
file = files.next();
if (file.getMimeType() !== "application/vnd.google-apps.spreadsheet") {
continue;
};
sourceSS = SpreadsheetApp.openById(file.getId());
sourcesheet = sourceSS.getSheetByName(srcSheetName);
//sourcesheet.getRange(start row, start column, numRows, number of Columns)
sourcerange = sourcesheet.getRange(2,1,sourcesheet.getLastRow()-1,13);
sourcevalues = sourcerange.getValues();
//Write all the new data to the end of this data
destrange = destinationSpreadsheet.getSheetByName("Master")
.getRange(destsheet.getLastRow()+1,1,sourcevalues.length,sourcevalues[0].length);
destrange.setValues(sourcevalues);
};
};
'''
我遇到麻烦的地方是
var pattern = /.Manual./;
srcSheetName = (pattern)
我希望它在 SrcSheetName 中使用的名称中找到任何带有“Manual”一词的文档。 执行此通配符的最佳方法是什么? 我尝试使用 ./Manual./ 但这没有用。
让我知道,加勒特·基德
获取所有工作表并使用String#includes或String#startsWith和Array#find获得正确的工作表:
sourceSS = SpreadsheetApp.openById(file.getId());
sourcesheet = sourceSS.getSheets().find(sheet =>
sheet.getName().includes("Manual"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.